<template>
  <!-- 检验规则维护（按照品号） -->
  <p-card :bordered="false">
    <!-- 查询区域 -->
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <p-form layout="inline" @keyup.enter.native="searchQuery">
        <p-row :gutter="24">


            <!--<p-col :xl="6" :lg="7" :md="8" :sm="24"  >

              <p-form-item label="*检验类型" style="border: 1px solid gray;border-top:none;border-right:none;">
                <p-select v-model="queryParam.inspectionType" placeholder="请选择检验类型">
                  <p-select-option
                          v-for="(item,index) in inspectTypeList"
                          :key="index"
                          :value="parseInt(item.value)"
                  >{{item.title}}</p-select-option>
                </p-select>
              </p-form-item>
            </p-col>-->

          <p-col :xl="6" :lg="7" :md="8" :sm="24">
            <p-form-item label="产品/物料编码">
              <p-input placeholder="请输入产品/物料编码" v-model="queryParam.mcode"></p-input>
            </p-form-item>
          </p-col>
          <p-col :xl="6" :lg="7" :md="8" :sm="24">
            <p-form-item label="产品/物料名称">
              <p-input placeholder="请输入产品/物料名称" v-model="queryParam.mname"></p-input>
            </p-form-item>
          </p-col>

          <p-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <p-button type="primary" @click="searchQuery" icon="search">查询</p-button>
              <p-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</p-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <p-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </p-col>

        </p-row>
      </p-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <p-button @click="openAddBtn" type="primary" icon="plus">新增</p-button>

      <template v-if="cgButtonList && cgButtonList.length>0" v-for="(item,index) in cgButtonList">
        <p-button v-if=" item.optType=='js' && (item.groupTag == null || item.groupTag == '' )" :key=" 'cgbtn'+index "
          @click="cgButtonJsHandler(item.buttonCode)" type="primary" :icon="item.buttonIcon">{{ item.buttonName }}
        </p-button>
        <p-button v-else-if=" item.optType=='action' && (item.groupTag == null || item.groupTag == '' )"
          :key=" 'cgbtn'+index " @click="cgButtonActionHandler(item.buttonCode)" type="primary" :icon="item.buttonIcon">
          {{ item.buttonName }}</p-button>
      </template>

      <!-- 高级查询区域 -->
      <j-super-query :fieldList="fieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>

      <p-dropdown v-for="(item,index) in groupTag" :key="index">
        <p-button>
          {{item.name}}
          <p-icon type="down" />
        </p-button>
        <p-menu slot="overlay">
          <template v-for="(items,indexs) in item.data">
            <p-menu-item v-if=" items.optType=='js' " :key="indexs" @click="cgButtonJsHandler(items.buttonCode)">
              <p-icon :type="items.buttonIcon" />{{items.buttonName}}
            </p-menu-item>
            <p-menu-item v-else-if=" items.optType=='action' " :key="indexs"
              @click="cgButtonActionHandler(items.buttonCode)">
              <p-icon :type="items.buttonIcon" />{{items.buttonName}}
            </p-menu-item>
          </template>
        </p-menu>
      </p-dropdown>

      <p-dropdown v-if="selectedRowKeys.length > 0">
        <p-menu slot="overlay">
          <p-menu-item key="1" @click="batchDel">
            <p-icon type="delete" />删除</p-menu-item>
        </p-menu>
        <p-button style="margin-left: 8px"> 批量操作
          <p-icon type="down" />
        </p-button>
      </p-dropdown>
    </div>
    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a
          style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>

        <span style="float:right;">
          <a @click="handleExportXls('检验规则维护（按品号）')">
            <p-icon type="download" />导出</a>
          <p-divider type="vertical" />
          <p-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader"
            :action="importExcelUrl" @change="handleImportExcel">
            <a>
              <p-icon type="import" />导入</a>
          </p-upload>
          <p-divider type="vertical" />
          <a @click="loadData()">
            <p-icon type="sync" />刷新</a>
          <p-divider type="vertical" />
          <p-popover title="自定义列" trigger="click" placement="leftBottom" :overlay-style="getWidth">
            <template slot="content">
              <p-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
                <p-row>
                  <template v-for="(item,index) in defColumns">
                    <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">
                      <p-col :span="12">
                        <p-checkbox :value="item.dataIndex">{{ item.title }}</p-checkbox>
                      </p-col>
                    </template>
                  </template>
                </p-row>
              </p-checkbox-group>
            </template>
            <a>
              <p-icon type="setting" />自定义列</a>
          </p-popover>
        </span>
      </div>

      <!-- 表格 -->
      <p-table ref="table" size="middle" bordered rowKey="id" :columns="columns" :scroll="tableScroll"
        :dataSource="dataSource" :pagination="ipagination" :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange,}"
               :customRow="clickThenSelect"
               :rowClassName="setRowClassName"
               @change="handleTableChange">

        <template slot="mcode" slot-scope="text,record">
          <a @click="openDetailBtn(record)">{{text}}</a>
        </template>
        <!-- 检验类型插槽 -->
        <template slot="inspectionType" slot-scope="text,record">
          <div @click="kan_zi_biao(record.inspectionType)" style="color:blue; cursor:pointer">{{data_text=data_dic(text,'inspectionType')}}</div>
        </template>


        <div slot="filterDropdown" slot-scope="{ setSelectedKeys, selectedKeys, confirm, clearFilters, column }"
          style="padding: 8px">
          <p-input v-ant-ref="c => (searchInput = c)" :placeholder="`请输入 ${column.title}`" :value="selectedKeys[0]"
            style="width: 188px; margin-bottom: 8px; display: block;"
            @change="e => setSelectedKeys(e.target.value ? [e.target.value] : [])" />
          <p-button type="primary" icon="search" size="small" style="width: 90px; margin-right: 8px"
            @click="() => handleSearch(selectedKeys, confirm, column.dataIndex)">
            确认
          </p-button>
          <p-button size="small" style="width: 90px" @click="() => handleReset(clearFilters)">
            取消
          </p-button>
        </div>
        <div slot="filterDropdownDate" slot-scope="{ setSelectedKeys, selectedKeys, confirm, clearFilters, column }"
          style="padding: 8px">
          <p-form-item :label="` ${column.title}`">
            <j-date :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择开始时间" class="query-group-cust"
              v-model="queryParam[`${column.dataIndex}_begin`]"></j-date>
            <span class="query-group-split-cust"></span>
            <j-date :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择结束时间" class="query-group-cust"
              v-model="queryParam[`${column.dataIndex}_end`]"></j-date>
          </p-form-item>
          <p-button type="primary" icon="search" size="small" style="width: 90px; margin-right: 8px"
            @click="() => handleSearchDate(selectedKeys, confirm, column.dataIndex)">
            确认
          </p-button>
          <p-button size="small" style="width: 90px"
            @click="() => handleResetDate(clearFilters,`${column.dataIndex}_begin`,`${column.dataIndex}_end`)">
            取消
          </p-button>
        </div>
        <p-icon slot="filterIcon" slot-scope="filtered" type="search"
          :style="{ color: filtered ? '#108ee9' : undefined }" />


        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无此图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="图片不存在"
            style="max-width:80px;font-size: 12px;font-style: italic;" />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无此文件</span>
          <p-button v-else :ghost="true" type="primary" icon="download" size="small" @click="uploadFile(text)">
            下载
          </p-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="openEditBtn(record)">编辑</a>

          <p-divider type="vertical" />
          <p-dropdown>
            <a class="ant-dropdown-link">更多
              <p-icon type="down" /></a>
            <p-menu slot="overlay">
              <p-menu-item>
                <p-popconfirm title="确定删除吗?" @confirm="() => deleteBtn(record.id)">
                  <a>删除</a>
                </p-popconfirm>
              </p-menu-item>
              <template v-if="cgButtonLinkList && cgButtonLinkList.length>0"
                v-for="(btnItem,btnIndex) in cgButtonLinkList">
                <p-menu-item :key=" 'cgbtnLink'+btnIndex " v-if="showLinkButton(btnItem,record)">
                  <a href="javascript:void(0);" @click="cgButtonLinkHandler(record,btnItem.buttonCode,btnItem.optType)">
                    <p-icon v-if="btnItem.buttonIcon" :type="btnItem.buttonIcon" />
                    {{ btnItem.buttonName }}
                  </a>
                </p-menu-item>
              </template>
            </p-menu>
          </p-dropdown>
        </span>
      </p-table>
    </div>

    <!-- 子表窗口 -->
    <!--<p-tabs :activeKey="zhi_biao_page">
      <p-tab-pane tab="检验规则维护（按品号）-首检" key="1" forceRender="true" >
        <mes-qc-inspect-rule-bmc-finsp-list :mainId="newSelectedMainId" />
      </p-tab-pane>
      <p-tab-pane tab="检验规则维护（按品号）-巡检" key="2" forceRender="true">
        <mes-qc-inspect-rule-patrol-list :mainId="newSelectedMainId" />
      </p-tab-pane>
      <p-tab-pane tab="检验规则维护（按品号）入库检/出厂检" key="3" forceRender="true">
        <mes-qc-inspect-rule-enter-out-list :mainId="newSelectedMainId" />
      </p-tab-pane>
      <p-tab-pane tab="检验规则维护（按品号）来料检" key="4" forceRender="true">
        <mes-qc-inspect-rule-come-list :mainId="newSelectedMainId" />
      </p-tab-pane>
    </p-tabs>-->

    <p-modal v-model="pModalVisible" :title="pTitle" :width="1300" :maskClosable="false" @ok="pModalOk">
      <p-form-model
              ref="ruleForm"
              :model="form"
              :rules="rules"
              :label-col="labelCol" :wrapper-col="wrapperCol"

      >

        <p-divider orientation="left">
          基础信息
        </p-divider>

        <p-form-model-item label="检验类型" prop="inspectionType">
          <p-select v-model="form.inspectionType" placeholder="请选择检验类型" style="width:350px" @change="inspectionTypeChange" :disabled="currentState==2" >
            <p-select-option
                    v-for="(item,index) in inspectTypeList"
                    :key="index"
                    :value="parseInt(item.value)"
            >{{item.title}}</p-select-option>
          </p-select>
        </p-form-model-item>

        <p-row :gutter="24"  >

          <p-col :span="12" >
            <p-form-model-item label="物料编码" prop="mid">
              <p-select
                      show-search
                      :value="form.mcode"
                      placeholder="可输入物料编码搜索"
                      style="width:250px"
                      :default-active-first-option="false"
                      :show-arrow="false"
                      :dropdownMatchSelectWidth="false"
                      :filter-option="false"
                      :not-found-content="null"
                      @search="productSearch"
                      :disabled="form.inspectionType==''"
              >

                <div slot="dropdownRender" >
                  <p-table
                          :columns="pruductSmallColumns"
                          :data-source="productList"
                          :pagination="false"
                          :customRow="productChange"
                          bordered
                          :scroll="{ x: 500, y: 300 }"
                  >
                  </p-table>
                </div>
               <!-- <p-select-option
                        v-for="(item,index) in productList"
                        :key="index"
                        :value="item.id"
                >{{item.mcode}}</p-select-option>-->
              </p-select>

              <p-spin  v-if="loadingVisible"/>
            </p-form-model-item>

          </p-col>

          <p-col :span="12" >
            <p-form-model-item label="物料名称" prop="mname">
              <p-input v-model="form.mname"  readOnly/>
            </p-form-model-item>
          </p-col>

          <p-col :span="12" >
            <p-form-model-item label="物料一级分类" prop="productOneType">
              <p-input v-model="form.productOneType" style="width:250px"  readOnly/> <p-spin v-if="loadingVisible1"/>
            </p-form-model-item>

          </p-col>

          <p-col :span="12" >
            <p-form-model-item label="物料二级分类" prop="productTwoType">
              <p-input v-model="form.productTwoType" style="width:250px"  readOnly/><p-spin v-if="loadingVisible1"/>
            </p-form-model-item>
          </p-col>
          <p-col :span="12" >
            <p-form-model-item label="物料三级分类" prop="productThreeType">
              <p-input v-model="form.productThreeType" style="width:250px"  readOnly/><p-spin v-if="loadingVisible1"/>
            </p-form-model-item>
          </p-col>

          <p-col :span="12" >
            <p-form-model-item label="" prop="" v-if="form.inspectionType!=5">
            </p-form-model-item>

            <p-form-model-item label="供应商代码" prop="custid" v-if="form.inspectionType==5">
              <p-select
                      show-search
                      :value="form.custid"
                      placeholder="可输入供应商代码搜索"
                      style="width:250px"
                      :default-active-first-option="false"
                      :show-arrow="false"
                      :filter-option="false"
                      :not-found-content="null"
                      @search="customerSearch1"
                      @change="customerChange1"
              >
                <p-select-option
                        v-for="(item,index) in customerList"
                        :key="index"
                        :value="item.id"
                >{{item.supno}}</p-select-option>
              </p-select>
              <p-spin  v-if="loadingVisible2"/>
            </p-form-model-item>
          </p-col>


          <p-col :span="12" >
            <p-form-model-item label="状态" prop="status">
              <p-radio-group v-model="form.status">
                <p-radio :value="1">
                  生效
                </p-radio>
                <p-radio :value="2">
                  失效
                </p-radio>
              </p-radio-group>
            </p-form-model-item>
          </p-col>

          <p-col :span="12" >
            <p-form-model-item label="" prop="" v-if="form.inspectionType!=5">
            </p-form-model-item>

            <p-form-model-item label="供应商名称" prop="custid" v-if="form.inspectionType==5">
              <p-select
                      show-search
                      :value="form.custid"
                      placeholder="可输入供应商名称搜索"
                      style="width:250px"
                      :default-active-first-option="false"
                      :show-arrow="false"
                      :filter-option="false"
                      :not-found-content="null"
                      @search="customerSearch2"
                      @change="customerChange1"
              >
                <p-select-option
                        v-for="(item,index) in customerList"
                        :key="index"
                        :value="item.id"
                >{{item.supname}}</p-select-option>
              </p-select>
              <p-spin  v-if="loadingVisible2"/>
            </p-form-model-item>
          </p-col>



        </p-row>

        <p-divider orientation="left">
          检验规则
        </p-divider>

        <p-table
                v-if="form.inspectionType==1&&currentState==1"
                :columns="firstCheckTableColumns"
                :data-source="firstCheckTableData"
                class="components-table-demo-nested"
                bordered
                style="margin-top:10px;"
                :rowSelection="{selectedRowKeys: firstCheckSelectRowKeys, onChange: firstCheckOnSelectChange,}"
        >
          <!--是否首检-->
          <template slot="isFirstCheck" slot-scope="text,record">
            <p-switch  checked-children="是" un-checked-children="否" v-model="text" @change="isFirstCheckChange(record)"/>
          </template>
         <!-- 是否线长确认-->
          <template slot="isLineleaderConfirm" slot-scope="text,record">
            <p-switch  checked-children="是" un-checked-children="否" v-model="text" @change="isLineleaderConfirmChange(record)"/>
          </template>
          <!--日期-->
          <template slot="isDate" slot-scope="text,record">
            <p-switch  checked-children="是" un-checked-children="否" v-model="text" @change="isDateChange(record)"/>
          </template>
          <!--品号-->
          <template slot="isMcode" slot-scope="text,record">
            <p-switch  checked-children="是" un-checked-children="否" v-model="text" @change="isMcodeChange(record)"/>
          </template>
          <!--线别-->
          <template slot="isLinetype" slot-scope="text,record">
            <p-switch  checked-children="是" un-checked-children="否" v-model="text" @change="isLinetypeChange(record)"/>
          </template>
          <!--工单-->
          <template slot="isMobillno" slot-scope="text,record">
            <p-switch  checked-children="是" un-checked-children="否" v-model="text" @change="isMobillnoChange(record)"/>
          </template>
          <!--机台-->
          <template slot="isMachineTable" slot-scope="text,record">
            <p-switch  checked-children="是" un-checked-children="否" v-model="text" @change="isMachineTableChange(record)"/>
          </template>
        </p-table>

        <p-table
                v-if="form.inspectionType==2&&currentState==1"
                :columns="xunCheckTableColumns"
                :data-source="firstCheckTableData"
                class="components-table-demo-nested"
                bordered
                style="margin-top:10px;"
                :rowSelection="{selectedRowKeys: firstCheckSelectRowKeys, onChange: firstCheckOnSelectChange,}"
                :scroll="firstCheckTableScroll"
        >

          <template slot="isRoundInspect" slot-scope="text,record">
            <p-switch  checked-children="是" un-checked-children="否" v-model="text" @change="isRoundInspectChange(record)"/>
          </template>

          <template slot="roundInspectMethod" slot-scope="text,record">
            <p-select v-model="record.roundInspectMethod"  :disabled="!record.isRoundInspect">
              <p-select-option :value="1">时间间隔</p-select-option>
              <p-select-option :value="2">比例</p-select-option>
            </p-select>
          </template>

          <template slot="roundInspectFrequency" slot-scope="text,record">
            <p-input :disabled="!record.isRoundInspect" v-model="record.roundInspectFrequency" type="number" style="width:70px" v-if="record.roundInspectMethod==1"  @change="fNumberChange(record)" />

            <p-input-group compact v-if="record.roundInspectMethod==2">
              <p-input :disabled="!record.isRoundInspect"   v-model="record.rifLeft" type="number" style="width:70px" @change="fNumberChange1(record)"/>
              ：
              <p-input :disabled="!record.isRoundInspect"   v-model="record.rifRight" type="number" style="width:70px;" @change="fNumberChange2(record)"/>
            </p-input-group>
          </template>

          <template slot="roundInspectTimequantum" slot-scope="text,record" >
            <div @click="clickTimePicker(record)">
              <p-time-picker style="width:100px;"
                              :allowClear="false"
                             :defaultValue="record.startTime"
                             @change="(val,dateStrings)=>changeTime(val,dateStrings,'startTime')"
                             format="HH:mm"/>
              -

              <p-time-picker style="width:100px;"
                             :allowClear="false"
                             :disabledHours="getDisabledHours"
                             :disabledMinutes="getDisabledMinutes"
                             :disabledSeconds="getDisabledSeconds"
                             :defaultValue="record.endTime"
                             @change="(val,dateStrings)=>changeTime(val,dateStrings,'endTime')"
                             format="HH:mm" />
            </div>

          </template>

          <template slot="rcInspectMethod" slot-scope="text,record" >
            <p-select v-model="record.rcInspectMethod"  :disabled="!record.isRoundInspect">
              <p-select-option :value="1">固定数量</p-select-option>
              <p-select-option :value="2">AQL</p-select-option>
            </p-select>
          </template>
          <template slot="rcInspectQty" slot-scope="text,record" >
            <p-input :disabled="!record.isRoundInspect" v-if="record.rcInspectMethod==1" v-model="record.rcInspectQty" type="number" style="width:70px" />
          </template>

          <template slot="aqlSimpleStandardName" slot-scope="text,record" >

            <p-select v-model="record.aqlSimpleStandardName" v-if="record.rcInspectMethod==2" :disabled="!record.isRoundInspect" showSearch>
              <p-select-option
                      v-for="(item,index) in aqlNameList"
                      :key="index"
                      :value="item"
              >{{item}}</p-select-option>
            </p-select>
          </template>

        </p-table>


        <p-row :guter="24" v-if="currentState==2&&(form.inspectionType==1||form.inspectionType==2)">

          <p-col :span="3">
            <p-button type="primary" @click="addLine">新增行</p-button>
            <p-popconfirm
                    v-if="xunCheckSelectRowKeys.length>0"
                    title="确定要删除所勾选项?"
                    ok-text="确定"
                    cancel-text="取消"
                    style="margin-left: 8px"
                    @confirm="delCheckProjectWhenEdit"
                    @cancel="cancel"
            >
              <p-button type="danger"   >删除</p-button>
            </p-popconfirm>


          </p-col>
        </p-row>

        <p-table
                v-if="form.inspectionType==1&&currentState==2"
                :columns="firstCheckTableColumns"
                :data-source="firstCheckTableData"
                class="components-table-demo-nested"
                :rowSelection="{selectedRowKeys: xunCheckSelectRowKeys, onChange: onXunCheckSelectChange,type:'checkbox'}"
                bordered
                style="margin-top:10px;"
        >
          <!--是否首检-->
          <template slot="isFirstCheck" slot-scope="text,record">
            <p-switch  checked-children="是" un-checked-children="否" v-model="text" @change="isFirstCheckChange(record)"/>
          </template>
          <!--是否线长确认-->
          <template slot="isLineleaderConfirm" slot-scope="text,record">
            <p-switch  checked-children="是" un-checked-children="否" v-model="text" @change="isLineleaderConfirmChange(record)"/>
          </template>
          <!--日期-->
          <template slot="isDate" slot-scope="text,record">
            <p-switch  checked-children="是" un-checked-children="否" v-model="text" @change="isDateChange(record)"/>
          </template>
          <!--品号-->
          <template slot="isMcode" slot-scope="text,record">
            <p-switch  checked-children="是" un-checked-children="否" v-model="text" @change="isMcodeChange(record)"/>
          </template>
          <!--线别-->
          <template slot="isLinetype" slot-scope="text,record">
            <p-switch  checked-children="是" un-checked-children="否" v-model="text" @change="isLinetypeChange(record)"/>
          </template>
          <!--工单-->
          <template slot="isMobillno" slot-scope="text,record">
            <p-switch  checked-children="是" un-checked-children="否" v-model="text" @change="isMobillnoChange(record)"/>
          </template>
          <!--机台-->
          <template slot="isMachineTable" slot-scope="text,record">
            <p-switch  checked-children="是" un-checked-children="否" v-model="text" @change="isMachineTableChange(record)"/>
          </template>
        </p-table>

        <p-table
                v-if="form.inspectionType==2&&currentState==2"
                :columns="xunCheckTableColumns"
                :data-source="firstCheckTableData"
                class="components-table-demo-nested"
                bordered
                style="margin-top:10px;"
                :rowSelection="{selectedRowKeys: xunCheckSelectRowKeys, onChange: onXunCheckSelectChange,type:'checkbox'}"
                :scroll="firstCheckTableScroll"
        >



          <template slot="isRoundInspect" slot-scope="text,record">
            <p-switch  checked-children="是" un-checked-children="否" v-model="text" @change="isRoundInspectChange(record)"/>
          </template>

          <template slot="roundInspectMethod" slot-scope="text,record">
            <p-select v-model="record.roundInspectMethod"  :disabled="!record.isRoundInspect">
              <p-select-option :value="1">时间间隔</p-select-option>
              <p-select-option :value="2">比例</p-select-option>
            </p-select>
          </template>

          <template slot="roundInspectFrequency" slot-scope="text,record">
            <p-input v-model="record.roundInspectFrequency" :disabled="!record.isRoundInspect" type="number" style="width:70px" v-if="record.roundInspectMethod==1"  @change="fNumberChange(record)" />

            <p-input-group compact v-if="record.roundInspectMethod==2">
              <p-input   v-model="record.rifLeft" :disabled="!record.isRoundInspect" type="number" style="width:70px" @change="fNumberChange1(record)"/>
              ：
              <p-input   v-model="record.rifRight" :disabled="!record.isRoundInspect" type="number" style="width:70px;" @change="fNumberChange2(record)"/>
            </p-input-group>
          </template>

          <template slot="roundInspectTimequantum" slot-scope="text,record" >
            <div @click="clickTimePicker(record)">
              <p-time-picker style="width:100px;"
                             :allowClear="false"
                             :defaultValue="record.startTime"
                             @change="(val,dateStrings)=>changeTime(val,dateStrings,'startTime')"
                             format="HH:mm"/>
              -

              <p-time-picker style="width:100px;"
                             :allowClear="false"
                             :disabledHours="getDisabledHours"
                             :disabledMinutes="getDisabledMinutes"
                             :disabledSeconds="getDisabledSeconds"
                             :defaultValue="record.endTime"
                             @change="(val,dateStrings)=>changeTime(val,dateStrings,'endTime')"
                             format="HH:mm" />
            </div>
           <!-- <div>{{record.roundInspectTimequantum}}</div>-->
          </template>


          <template slot="rcInspectMethod" slot-scope="text,record" >
            <p-select v-model="record.rcInspectMethod"  :disabled="!record.isRoundInspect">
              <p-select-option :value="1">固定数量</p-select-option>
              <p-select-option :value="2">AQL</p-select-option>
            </p-select>
          </template>


          <template slot="rcInspectQty" slot-scope="text,record" >
            <p-input :disabled="!record.isRoundInspect" v-if="record.rcInspectMethod==1" v-model="record.rcInspectQty" type="number" style="width:70px" />
          </template>

          <template slot="aqlSimpleStandardName" slot-scope="text,record" >

            <p-select  v-model="record.aqlSimpleStandardName" v-if="record.rcInspectMethod==2" showSearch :disabled="!record.isRoundInspect">
              <p-select-option
                      v-for="(item,index) in aqlNameList"
                      :key="index"
                      :value="item"
              >{{item}}</p-select-option>
            </p-select>
          </template>



        </p-table>


        <p-row :gutter="24"  v-if="!loadingVisible1&&form.mid&&form.inspectionType&&form.inspectionType!=1&&form.inspectionType!=2">
          <p-form-model-item label="检验属性" prop="inspectAttribute">
            <p-radio-group v-model="form.inspectAttribute">
              <p-radio
                      v-for="(item,index) in inspectAttributeList"
                      :key="index"
                      :value="parseInt(item.value)"
              >
                {{item.title}}
              </p-radio>
            </p-radio-group>
          </p-form-model-item>


          <p-form-model-item label="加严系数" prop="tightCoefficient" v-if="form.inspectAttribute==1">
            <p-input v-model="form.tightCoefficient" @change="tightCoefficientChange" type="number" style="width:150px"></p-input>
          </p-form-model-item>

          <p-form-model-item label="是否动态调整" prop="isDynamicRegulation">
            <!--<p-radio-group v-model="form.isDynamicRegulation">
              <p-radio :value="1">
                是
              </p-radio>
              <p-radio :value="2">
                否
              </p-radio>
            </p-radio-group>-->

            <p-switch checked-children="是" un-checked-children="否" v-model="form.isDynamicRegulation" />
          </p-form-model-item>

          <p-form-model-item label="动态调整规则" prop="dynamicAdjustment">
            <p-input-group compact>
              <p-input addon-before="正常（N1）:" v-model="form.normalN1"  type="number" style="width:220px;margin-right: 10px" @change="numberChange4" :disabled="!form.isDynamicRegulation"></p-input>
              <p-input addon-before="直通（N2）:" v-model="form.passThroughN2"  type="number" style="width:220px"  @change="numberChange5" :disabled="!form.isDynamicRegulation"></p-input>
            </p-input-group>
          </p-form-model-item>

          <p-form-model-item label="是否需要供应商出厂报告" prop="isNeedCustoutrc" v-if="form.inspectionType==5">

            <p-switch checked-children="是" un-checked-children="否" v-model="form.isNeedCustoutrc" />
          </p-form-model-item>

          <p-form-model-item label="抽样方式" prop="simplingMethod" >
            <p-radio-group v-model="form.simplingMethod" @change="simplingMethodSelectChange">
              <p-radio
                      v-for="(item,index) in simplingMethodList"
                      :key="index"
                      :value="parseInt(item.value)"
              >
                {{item.title}}
              </p-radio>
            </p-radio-group>
          </p-form-model-item>

          <p-form-model-item label="正常抽样数量" prop="normalSimplingQty" v-if="form.simplingMethod==1">
            <p-input-group compact >
              <p-select v-model="form.normalSimplingQtyType" @change="normalSimplingQtyTypeChange">
                <p-select-option :value="1">
                  数量
                </p-select-option>
                <p-select-option :value="2">
                  比例
                </p-select-option>
              </p-select>
              <p-input v-model="form.normalSimplingQty" v-if="form.normalSimplingQtyType==1" style="width:160px" type="number" @change="numberChange1"/>

              <p-input   v-model="form.normalSimplingQtyLeft" type="number" style="width:80px" v-if="form.normalSimplingQtyType==2" @change="numberChange2"/>
              <p-input
                      style=" width: 30px;  pointer-events: none;"
                      placeholder=":"
                      disabled
                      v-if="form.normalSimplingQtyType==2"
              />
              <p-input   v-model="form.normalSimplingQtyRight" type="number" style="width:80px;" v-if="form.normalSimplingQtyType==2" @change="numberChange3"/>
            </p-input-group>






          </p-form-model-item>


          <p-form-model-item label="AQL抽样标准" prop="normalSimplingQty" v-if="form.simplingMethod==2">
            <p-select v-model="form.aqlSimpleStandardName"  showSearch>
              <p-select-option
                      v-for="(item,index) in aqlNameList"
                      :key="index"
                      :value="item"
              >{{item}}</p-select-option>
            </p-select>
          </p-form-model-item>

        </p-row>


      </p-form-model>
    </p-modal>


    <p-drawer
            title="详情"
            placement="right"
            :closable="false"
            :width="900"
            :visible="detailVisible"
            @close="closeDetailBtn"
    >
      <p-divider orientation="left">
        主信息
      </p-divider>

      <p-descriptions  bordered size="small">
        <p-descriptions-item label="产品/物料编码">
          {{de.mcode}}
        </p-descriptions-item>
        <p-descriptions-item label="产品/物料名称" :span="2">
          {{de.mname}}
        </p-descriptions-item>
        <p-descriptions-item label="物料一级分类">
          {{de.productOneType}}
        </p-descriptions-item>
        <p-descriptions-item label="物料一级分类编码" :span="2">
          {{de.productOneTypeCode}}
        </p-descriptions-item>
        <p-descriptions-item label="物料二级分类">
          {{de.productTwoType}}
        </p-descriptions-item>
        <p-descriptions-item label="物料二级分类编码" :span="2">
          {{de.productTwoTypeCode}}
        </p-descriptions-item>
        <p-descriptions-item label="物料三级分类">
          {{de.productThreeType}}
        </p-descriptions-item>
        <p-descriptions-item label="物料三级分类编码" :span="2">
          {{de.productThreeTypeCode}}
        </p-descriptions-item>

        <p-descriptions-item label="供应商代码" v-if="de.inspectionType==5">
          {{de.custno}}
        </p-descriptions-item>
        <p-descriptions-item label="供应商名称" v-if="de.inspectionType==5" :span="2">
          {{de.custname}}
        </p-descriptions-item>
        <p-descriptions-item label="检验类型" >
          <div style="color:blue">{{inspectTypeMap[de.inspectionType]?inspectTypeMap[de.inspectionType].title:''}}</div>
        </p-descriptions-item>
        <p-descriptions-item label="状态" :span="2">
          <div v-if="!de.status" >/</div>
          <p-tag v-else-if="de.status==1" color="green"><p-icon type="check-circle" />生效</p-tag>
          <p-tag v-else-if="de.status==2" color="red"><p-icon type="close-circle" />失效</p-tag>
        </p-descriptions-item>
        <p-descriptions-item label="创建者" :span="2">
          {{de.createBy}}
        </p-descriptions-item>
        <p-descriptions-item label="创建日期">
          {{de.createTime?dayjs(de.createTime).format('YYYY-MM-DD'):''}}
        </p-descriptions-item>

        <p-descriptions-item label="修改者" :span="2">
          {{de.updateBy}}
        </p-descriptions-item>
        <p-descriptions-item label="更新日期">
          {{de.updateTime?dayjs(de.updateTime).format('YYYY-MM-DD'):''}}
        </p-descriptions-item>


      </p-descriptions>

      <p-divider orientation="left">
        检验规则
      </p-divider>

      <p-descriptions  bordered v-if="de.inspectionType!=2&&de.inspectionType!=1">
        <p-descriptions-item label="检验属性">
          {{de.inspectAttribute?inspectAttributeMap[de.inspectAttribute]?inspectAttributeMap[de.inspectAttribute].title:'':''}}
        </p-descriptions-item>
        <p-descriptions-item label="加严系数" v-if="de.inspectAttribute==1">
          {{de.tightCoefficient}}
        </p-descriptions-item>
        <p-descriptions-item label="是否动态调整">
          {{de.isDynamicRegulation==1?'是':'否'}}
        </p-descriptions-item>
        <p-descriptions-item label="正常（N1）">
          {{de.normalN1}}
        </p-descriptions-item>
        <p-descriptions-item label="直通（N2）">
          {{de.passThroughN2}}
        </p-descriptions-item>
        <p-descriptions-item label="是否需要供应商出厂报告">
          {{de.isNeedCustoutrc==1?'是':'否'}}
        </p-descriptions-item>
        <p-descriptions-item label="抽样方式">
          {{de.simplingMethod?de.simplingMethod==1?'固定数量':'AQL':''}}
        </p-descriptions-item>

        <p-descriptions-item label="正常抽样数量" v-if="de.simplingMethod==1">
          {{de.normalSimplingQty}}
        </p-descriptions-item>
        <p-descriptions-item label="AQL抽样标准" v-if="de.simplingMethod==2">
          {{de.aqlSimpleStandardName}}
        </p-descriptions-item>
      </p-descriptions>


      <p-table
              v-if="de.inspectionType==2"
              :columns="xunCheckTableColumns2"
              :data-source="de.mesQcInspectRuleBmcFinspList"

              class="components-table-demo-nested"
              bordered

              style="margin-top:10px;"
      >

        <template slot="isRoundInspect" slot-scope="text,record">
          <p-switch  checked-children="是" un-checked-children="否" v-model="text" disabled/>
        </template>

        <template slot="roundInspectMethod" slot-scope="text,record">
          <div v-if="text==1">时间间隔</div>
          <div v-else-if="text==2">比例</div>
        </template>
        <template slot="rcInspectMethod" slot-scope="text,record">
          <div v-if="text==1">固定数量</div>
          <div v-else-if="text==2">AQL</div>
        </template>


        <template slot="rcInspectQty" slot-scope="text,record">
          <div v-if="record.rcInspectMethod==1">{{text}}</div>
        </template>

        <template slot="aqlSimpleStandardName" slot-scope="text,record">
          <div v-if="record.rcInspectMethod==2">{{text}}</div>
        </template>


      </p-table>

      <p-table
              v-if="de.inspectionType==1"
              :columns="firstCheckTableColumns"
              :data-source="de.mesQcInspectRuleBmcFinspList"
              class="components-table-demo-nested"
              bordered
              style="margin-top:10px;"
      >
        <!--是否首检-->
        <template slot="isFirstCheck" slot-scope="text,record">
          <p-switch  checked-children="是" un-checked-children="否" disabled v-model="text" />
        </template>
        <!--是否线长确认-->
        <template slot="isLineleaderConfirm" slot-scope="text,record">
          <p-switch  checked-children="是" un-checked-children="否" disabled v-model="text"/>
        </template>
        <!--日期-->
        <template slot="isDate" slot-scope="text,record">
          <p-switch  checked-children="是" un-checked-children="否" disabled v-model="text" />
        </template>
        <!--品号-->
        <template slot="isMcode" slot-scope="text,record">
          <p-switch  checked-children="是" un-checked-children="否" disabled v-model="text" />
        </template>
        <!--线别-->
        <template slot="isLinetype" slot-scope="text,record">
          <p-switch  checked-children="是" un-checked-children="否" disabled v-model="text" />
        </template>
        <!--工单-->
        <template slot="isMobillno" slot-scope="text,record">
          <p-switch  checked-children="是" un-checked-children="否" disabled v-model="text" />
        </template>
        <!--机台-->
        <template slot="isMachineTable" slot-scope="text,record">
          <p-switch  checked-children="是" un-checked-children="否" disabled v-model="text" />
        </template>

      </p-table>

    </p-drawer>

    <p-modal
            v-model="addCPModalVisible"
            title="新增检验规则"
            :width="1200"
            @ok="addReadyCPBtn">


      <p-table
              v-if="form.inspectionType==1"
              :columns="firstCheckTableColumns"
              :data-source="readyAddCPdata"
              class="components-table-demo-nested"
              :loading="addcpLoding"
              bordered
              style="margin-top:10px;"
              :rowSelection="{selectedRowKeys: readyAddCPSelectRowKeys, onChange: readyAddCPOnSelectChange,}"
      >


        <!--是否首检-->
        <template slot="isFirstCheck" slot-scope="text,record">

          <p-switch  checked-children="是" un-checked-children="否" v-model="record.isFirstCheck==1" disabled/>
        </template>
        <!-- 是否线长确认-->
        <template slot="isLineleaderConfirm" slot-scope="text,record">
          <p-switch  checked-children="是" un-checked-children="否" v-model="record.isLineleaderConfirm==1" disabled/>
        </template>
        <!--日期-->
        <template slot="isDate" slot-scope="text,record">
          <p-switch  checked-children="是" un-checked-children="否" v-model="record.isDate==1" disabled/>
        </template>
        <!--品号-->
        <template slot="isMcode" slot-scope="text,record">

          <p-switch  checked-children="是" un-checked-children="否" v-model="record.isMcode==1" disabled/>
        </template>
        <!--线别-->
        <template slot="isLinetype" slot-scope="text,record">

          <p-switch  checked-children="是" un-checked-children="否" v-model="record.isLinetype==1" disabled/>
        </template>
        <!--工单-->
        <template slot="isMobillno" slot-scope="text,record">
          <p-switch  checked-children="是" un-checked-children="否" v-model="record.isMobillno==1" disabled/>
        </template>
        <!--机台-->
        <template slot="isMachineTable" slot-scope="text,record">
          <p-switch  checked-children="是" un-checked-children="否" v-model="record.isMachineTable==1" disabled/>
        </template>
      </p-table>

      <p-table
              v-if="form.inspectionType==2"
              :columns="xunCheckTableColumns"
              :data-source="readyAddCPdata"
              class="components-table-demo-nested"
              :loading="addcpLoding"
              bordered
              style="margin-top:10px;"
              :rowSelection="{selectedRowKeys: readyAddCPSelectRowKeys, onChange: readyAddCPOnSelectChange,}"
              :scroll="firstCheckTableScroll"
      >






        <template slot="isRoundInspect" slot-scope="text,record">
          <p-switch  checked-children="是" un-checked-children="否" v-model="record.isRoundInspect==1" disabled/>
        </template>

        <template slot="roundInspectMethod" slot-scope="text,record">
          <div v-if="!record.roundInspectMethod"></div>
          <div v-else-if="record.roundInspectMethod==1">时间间隔</div>
          <div v-else-if="record.roundInspectMethod==2">比例</div>
        </template>

        <template slot="roundInspectFrequency" slot-scope="text,record">
          <div>{{record.roundInspectFrequency}}</div>
        </template>

        <template slot="roundInspectTimequantum" slot-scope="text,record" >
          <div>{{record.roundInspectTimequantum}}</div>
        </template>

        <template slot="rcInspectMethod" slot-scope="text,record" >
          <div v-if="!record.rcInspectMethod"></div>
          <div v-else-if="record.rcInspectMethod==1">固定数量</div>
          <div v-else-if="record.rcInspectMethod==2">AQL</div>
        </template>
        <template slot="rcInspectQty" slot-scope="text,record" >
          <div>{{record.rcInspectQty}}</div>
        </template>

        <template slot="aqlSimpleStandardName" slot-scope="text,record" >
          <div>{{record.aqlSimpleStandardName}}</div>
        </template>

      </p-table>
    </p-modal>

    <mesQcInspectRuleBymcode-modal ref="modalForm" :EnhanceJS="EnhanceJS" @ok="modalFormOk">
    </mesQcInspectRuleBymcode-modal>
    <!-- 弹出窗 -->
    <Fx-compontens-modal @ok="modalFormOk" ref="modalCompon" :getList="queryInfo" :title="title"
      :dictOptions="dictOptions"></Fx-compontens-modal>
  </p-card>
</template>

<script>
  // 导入的子组件
   import MesQcInspectRuleBmcFinspList from './MesQcInspectRuleBmcFinspList'
  import MesQcInspectRulePatrolList from './MesQcInspectRulePatrolList'
  import MesQcInspectRuleEnterOutList from './MesQcInspectRuleEnterOutList'
  import MesQcInspectRuleComeList from './MesQcInspectRuleComeList'

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { api } from '@/api/manage'
  import JSuperQuery from '@/components/jeecg/JSuperQuery.vue'
  import { filterObj } from '@/utils/util'
  import MesQcInspectRuleBymcodeModal from './modules/MesQcInspectRuleBymcodeModal'
  import Vue from 'vue'
  import  dayjs   from 'dayjs';
  import JDictSelectTag from '@/components/dict/JDictSelectTag.vue'
  import { initDictOptions, filterMultiDictText } from '@/components/dict/JDictSelectUtil'
  import ButtonExpHandler from '@/components/jeecgbiz/modules/ButtonExpHandler'
  import { postAction, getAction, deleteAction,putAction } from '@/api/manage'
  import FxCompontensModal from "@/components/jeecgbiz/FxCompontensModal"
  import moment from "moment";

  //高级查询modal需要参数
  const superQueryFieldList = [
    {
      value: 'mcode',
      text: '产品/物料编码',
      type: 'string'
    },
    {
      value: 'mname',
      text: '产品/物料名称',
      type: 'string'
    },
    {
      value: 'productOneType',
      text: '物料一级分类',
      type: 'String'
    },
    {
      value: 'productOneTypeCode',
      text: '物料一级分类编码',
      type: 'String'


    },
    {
      value: 'productTwoType',
      text: '物料二级分类',
      type: 'String'

    },
    {
      value: 'productTwoTypeCode',
      text: '物料二级分类编码',
      type: 'String'
    },
    {
      value: 'productThreeType',
      text: '物料三级分类',
      type: 'String'

    },
    {
      value: 'productThreeTypeCode',
      text: '物料三级分类编码',
      type: 'String'
    },
    {
      value: 'inspectionType',
      text: '检验类型',
      type: 'select',
      dictCode: 'inspect_type'
    },
    {
      value: 'custno',
      text: '供应商编码',
      type: 'string'
    },
    {
      value: 'custname',
      text: '供应商名称',
      type: 'string'
    },
    {
      value: 'status',
      text: '状态',
      type: 'select',
      dictCode: 'mes_status'
    },
    {
      value: 'createBy',
      text: '创建人',
      type: 'string'
    },
    {
      value: 'createTime',
      text: '创建日期',
      type: 'Date'
    },
    {
      value: 'updateBy',
      text: '更新人',
      type: 'string'
    },
    {
      value: 'updateTime',
      text: '更新日期',
      type: 'Date'
    },
    {
      value: 'remark',
      text: '备注',
      type: 'string'
    },
  ]

  export default {
    name: "MesQcInspectRuleBymcodeList",
    mixins: [JeecgListMixin],
    components: {
      JSuperQuery,
      JDictSelectTag,
      MesQcInspectRuleBmcFinspList,
      MesQcInspectRulePatrolList,
      MesQcInspectRuleEnterOutList,
      MesQcInspectRuleComeList,
      FxCompontensModal,
      MesQcInspectRuleBymcodeModal
    },
    data() {
      return {
        rowId:0,
        zhi_biao_page: '1',/*控制显示那页子表*/
        fieldList: superQueryFieldList,
        superQueryFlag: false,
        superQueryParams: '',
        description: '检验规则维护（按品号）管理页面',
        EnhanceJS: '',
        cgButtonLinkList: [],
        cgButtonList: [],

        de:{},

        addCPModalVisible:false,
        detailVisible:false,

        loadingVisible:false,
        loadingVisible1:false,
        loadingVisible2:false,
        inspectTypeList:[],
        inspectTypeMap:[],
        productList:[],
        productMap:[],

        customerList:[],
        customerMap:[],

        inspectAttributeList:[],
        inspectAttributeMap:[],
        simplingMethodList:[],
        simplingMethodMap:[],

        aqlDataList:[],
        aqlDataMap:[],


        pModalVisible:false,
        pTitle:'',
        labelCol: { span: 6 },
        wrapperCol: { span: 16 },
        currentState:1,

        editP:{},
        pruductSmallColumns:[
          {
            title: '物料编码',
            align: 'center',
            dataIndex: 'mcode',
          },
          {
            title: '物料名称',
            align: 'center',
            dataIndex: 'mname',
          },
        ],
        form: {
          inspectionType:'',
          status:1,
          mid:'',
          mcode:'',
          mname:'',
          productOneTypeCode:'',
          productOneType:'',
          productTwoTypeCode:'',
          productTwoType:'',
          productThreeTypeCode:'',
          productThreeType:'',
          custid:'',
          custno:'',
          custname:'',
          inspectAttribute:3,
          tightCoefficient:'',
          isDynamicRegulation:true,
          normalN1:'',
          passThroughN2:'',
          isNeedCustoutrc:false,
          simplingMethod:1,
          normalSimplingQtyType:1,
          normalSimplingQty:'',
          normalSimplingQtyLeft:0,
          normalSimplingQtyRight:0,
          aqlSimpleId:'',
          aqlSimpleStandardName:'',
        },

        rules: {
          inspectionType: [{ required: true, message: '请选择检验类型', trigger: 'change' }],
          status: [{ required: true, message: '请选择状态', trigger: 'change' }],
          mid: [{ required: true, message: '请选择物料', trigger: 'change' }],
        },


        firstCheckTableColumns:[
          {
            title: "序号",
            dataIndex: "",
            key: "rowIndex",
            width: 60,
            align: "center",
            customRender: function (t, r, index) {
              return parseInt(index) + 1;
            },

          },
          {
            title: '一级工序名称',
            align: 'center',
            dataIndex: 'processOneName',
          },
          {
            title: '一级工序编码',
            align: 'center',
            dataIndex: 'processOneCode',

          },
          {
            title: '二级工序名称',
            align: 'center',
            dataIndex: 'processTwoName',

          },
          {
            title: '二级工序编码',
            align: 'center',
            dataIndex: 'processTwoCode',

          },

          {
            title: '是否首检',
            align: 'center',
            dataIndex: 'isFirstCheck',
            scopedSlots: { customRender: 'isFirstCheck' },
          },

          {
            title: '是否线长确认',
            align: 'center',
            dataIndex: 'isLineleaderConfirm',
            scopedSlots: { customRender: 'isLineleaderConfirm' },
          },
          {
            title:'首检触发配置条件',
            children:[
              {
                title: '日期',
                align: 'center',
                dataIndex: 'isDate',
                scopedSlots: { customRender: 'isDate' },
              },
              {
                title: '品号',
                align: 'center',
                dataIndex: 'isMcode',
                scopedSlots: { customRender: 'isMcode' },
              },
              {
                title: '线别',
                align: 'center',
                dataIndex: 'isLinetype',
                scopedSlots: { customRender: 'isLinetype' },
              },
              {
                title: '工单',
                align: 'center',
                dataIndex: 'isMobillno',
                scopedSlots: { customRender: 'isMobillno' },
              },
              {
                title: '机台',
                align: 'center',
                dataIndex: 'isMachineTable',
                scopedSlots: { customRender: 'isMachineTable' },
              },
            ],
          },


        ],
        firstCheckTableData:[],
        firstCheckTableDataMap:[],

        firstCheckSelectRowKeys:[],
        firstCheckSelectRows:[],

        readyAddCPdata:[],
        readyAddCPdataMap:[],

        addcpLoding:true,


        readyAddCPSelectRowKeys:[],
        readyAddCPSelectRows:[],

        xunCheckSelectRowKeys:[],
        xunCheckSelectRows:[],

        xunCheckTableColumns2:[
          {
            title: "序号",
            dataIndex: "",
            key: "rowIndex",
            width: 60,
            align: "center",
            customRender: function (t, r, index) {
              return parseInt(index) + 1;
            },
          },

          {
            title: '一级工序名称',
            align: 'center',
            dataIndex: 'processOneName',

          },
          {
            title: '一级工序编码',
            align: 'center',
            dataIndex: 'processOneCode',

          },
          {
            title: '二级工序名称',
            align: 'center',
            dataIndex: 'processTwoName',
          },
          {
            title: '二级工序编码',
            align: 'center',
            dataIndex: 'processTwoCode',
          },

          {
            title: '是否巡检',
            align: 'center',
            dataIndex: 'isRoundInspect',
            scopedSlots: { customRender: 'isRoundInspect' },
          },
          {
            title: '触发巡检方式',
            align: 'center',
            dataIndex: 'roundInspectMethod',
            scopedSlots: { customRender: 'roundInspectMethod' },

          },
          {
            title: '巡检频率（小时/次）',
            align: 'center',
            dataIndex: 'roundInspectFrequency',
            scopedSlots: { customRender: 'roundInspectFrequency' },
          },
          {
            title: '巡检时间段',
            align: 'center',
            dataIndex: 'roundInspectTimequantum',
            scopedSlots: { customRender: 'roundInspectTimequantum' },
          },
          {
            title: '巡检抽样方式',
            align: 'center',
            dataIndex: 'rcInspectMethod',
            scopedSlots: { customRender: 'rcInspectMethod' },

          },
          {

            title: '巡检抽样数量',
            align: 'center',
            dataIndex: 'rcInspectQty',
            scopedSlots: { customRender: 'rcInspectQty' },
          },

          {
            title: 'AQL抽样标准',
            align: 'center',
            dataIndex: 'aqlSimpleStandardName',
            scopedSlots: { customRender: 'aqlSimpleStandardName' },
          },
        ],

        xunCheckTableColumns:[
          {
            title: "序号",
            dataIndex: "",
            key: "rowIndex",
            width: 60,
            align: "center",
            customRender: function (t, r, index) {
              return parseInt(index) + 1;
            },
            fixed:true,
          },

          {
            title: '一级工序名称',
            width: 150,
            align: 'center',
            dataIndex: 'processOneName',
            fixed:true,

          },
          {
            title: '一级工序编码',
            width: 100,
            align: 'center',
            dataIndex: 'processOneCode',
            fixed:true,
          },
          {
            title: '二级工序名称',
            width: 150,
            align: 'center',
            dataIndex: 'processTwoName',
            fixed:true,
          },
          {
            title: '二级工序编码',
            width: 100,
            align: 'center',
            dataIndex: 'processTwoCode',
            fixed:true,
          },

          {
            title: '是否巡检',
            width: 120,
            align: 'center',
            dataIndex: 'isRoundInspect',
            scopedSlots: { customRender: 'isRoundInspect' },
          },
          {
            title: '触发巡检方式',
            width: 150,
            align: 'center',
            dataIndex: 'roundInspectMethod',
            scopedSlots: { customRender: 'roundInspectMethod' },

          },
          {
            title: '巡检频率（小时/次）',
            width: 200,
            align: 'center',
            dataIndex: 'roundInspectFrequency',
            scopedSlots: { customRender: 'roundInspectFrequency' },
          },
          {
            title: '巡检时间段',
            align: 'center',
            width: 270,
            dataIndex: 'roundInspectTimequantum',
            scopedSlots: { customRender: 'roundInspectTimequantum' },
          },
          {
            title: '巡检抽样方式',
            width: 140,
            align: 'center',
            dataIndex: 'rcInspectMethod',
            scopedSlots: { customRender: 'rcInspectMethod' },

          },
          {

            title: '巡检抽样数量',
            width: 140,
            align: 'center',
            dataIndex: 'rcInspectQty',
            scopedSlots: { customRender: 'rcInspectQty' },
          },

          {

            title: 'AQL抽样标准',
            width: 200,
            align: 'center',
            dataIndex: 'aqlSimpleStandardName',
            scopedSlots: { customRender: 'aqlSimpleStandardName' },
          },
        ],
        xunCheckTableData:[],
        aqlNameList:[],

        currentKey:0,


        title: '',//存表名
        groupTag: [],
        queryInfo: [],
        code: '',
        // 表头
        columns: [],
        //列设置
        settingColumns: [],
        //列定义
        defColumns: [
          {
            title: "序号",
            dataIndex: "",
            key: "rowIndex",
            width: 60,
            align: "center",
            customRender: function (t, r, index) {
              return parseInt(index) + 1;
            },
          },
          {
            title: '产品/物料编码',
            align: 'center',
            dataIndex: 'mcode',
            scopedSlots: { customRender: "mcode" },
          },
          {
            title: '产品/物料名称',
            align: 'center',
            dataIndex: 'mname',
          },
          {
            title: '检验类型',
            align: 'center',
            dataIndex: 'inspectionType',
            scopedSlots: { customRender: "inspectionType" },/*添加插槽*/

          },
          {
            title: '供应商代码',
            align: 'center',
            dataIndex: 'custno',

          },
          {
            title: '供应商名称',
            align: 'center',
            dataIndex: 'custname',

          },
          {
            title: '物料一级分类',
            align: 'center',
            dataIndex: 'productOneType',
          },
          {
            title: '物料一级分类编码',
            align: 'center',
            dataIndex: 'productOneTypeCode',

          },
          {
            title: '物料二级分类',
            align: 'center',
            dataIndex: 'productTwoType',

          },
          {
            title: '物料二级分类编码',
            align: 'center',
            dataIndex: 'productTwoTypeCode',

          },
          {
            title: '物料三级分类',
            align: 'center',
            dataIndex: 'productThreeType',

          },
          {
            title: '物料三级分类编码',
            align: 'center',
            dataIndex: 'productThreeTypeCode',

          },



          {
            title: '创建人',
            align: 'center',
            dataIndex: 'createBy',
          },
          {
            title: '创建日期',
            align: 'center',
            dataIndex: 'createTime',
            customRender: function (text) {
              return !text ? "" : (text.length > 10 ? text.substr(0, 10) : text)
            },
          },
          {
            title: '更新人',
            align: 'center',
            dataIndex: 'updateBy',
          },
          {
            title: '更新日期',
            align: 'center',
            dataIndex: 'updateTime',
            customRender: function (text) {
              return !text ? "" : (text.length > 10 ? text.substr(0, 10) : text)
            },
          },

          {
            title: '备注',
            align: 'center',
            dataIndex: 'remark',
          },
          {
            title: '状态',
            align: 'center',
            dataIndex: 'status',
            customRender: (text) => {
              if (!text) {
                return ''
              } else {
                // return filterMultiDictText(this.dictOptions['status'], text + "")
                let data = filterMultiDictText(this.dictOptions['status'], text + "");
                if(data=="生效"){
                  return <p-tag  color="green"><p-icon type="check-circle" />{data}</p-tag>
                }else {
                  return <p-tag color="red"><p-icon type="close-circle" />{data}</p-tag>
                }
              }
            },
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            scopedSlots: { customRender: 'action' },
          },

        ],
        url: {
          list: '/mes-quality/mesQcInspectRuleBymcode/list',
          delete: '/mes-quality/mesQcInspectRuleBymcode/delete',
          deleteBatch: '/mes-quality/mesQcInspectRuleBymcode/deleteBatch',
          exportXlsUrl: '/mes-quality/mesQcInspectRuleBymcode/exportXls',
          importExcelUrl: '/mes-quality/mesQcInspectRuleBymcode/importExcel',
          getColumns: '/mes-quality/online/cgform/api/getColumns/',
          buttonAction: '/mes-quality/online/cgform/api/doButton',
        },
        dictOptions: {//数据字典
          inspectionType: [],
          status: [],
        },

        /* 分页参数 */
        ipagination: {
          current: 1,
          pageSize: 10,
          pageSizeOptions: ['10', '20', '50'],
          showTotal: (total, range) => {
            return range[0] + "-" + range[1] + " 共" + total + "条"
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0
        },
        selectedMainId: ''

      }
    },
    computed: {
      importExcelUrl: function () {
        return `${api.test}${this.url.importExcelUrl}`;
      },
      getWidth: function () {
        if (this.defColumns.length > 14) {
          return { width: '500px' }
        }
      },
      newSelectedMainId: function () {
        if (typeof (this.selectedMainId) == 'number') {
          return this.selectedMainId.toString()
        } else {
          return this.selectedMainId
        }
      },
      tableScroll: function () {
        if (this.columns.length > 13) {
          return { x: this.columns.length * 150 - 450 }
        }
      },


      firstCheckTableScroll: function () {

          return { x: 1700 }

      }
    },

    created() {
      this.initInspectAttributeList();
      this.initSimplingMethodList();
      this.initAqlNameList();
      this.initProductList({});
      this.initInspectTypeList();
      this.initButtonList();
      this.initColumns();
      this.setdefColumns();
      this.initCustomerList('','');
    },
    updated() {
    },

    methods: {
      handleSearch1(selectedKeys, confirm, dataIndex) {
        confirm();
        this.searchText = selectedKeys[0];
        this.searchedColumn = dataIndex;
      },

      handleReset1(clearFilters) {
        clearFilters();
        this.searchText = '';
      },
      //封装listToMap
      listToMap(list,name){
        let map = {};
        for(let i in list){
          map[list[i][name]] = list[i];
        }
        return map;
      },
      initInspectAttributeList(){
        getAction('/basic-business/sys/dict/queryDictItemsByCode',{dictCode:'inspect_attribute '}).then(res=>{
          if(res.success){
            this.inspectAttributeList = res.data;
            this.inspectAttributeMap = this.listToMap(this.inspectAttributeList,'value');
          }
        })
      },
      dayjs,
      addReadyCPBtn(){

        let data = this.readyAddCPSelectRows;
        data.forEach(item=>{
          item.mesInspectRuleBymcodeId = this.editP.id;
          item.isFirstCheck = item.isFirstCheck?1:2;
          item.isLineleaderConfirm = item.isLineleaderConfirm?1:2;
          item.isDate = item.isDate?1:2;
          item.isMcode = item.isMcode?1:2;
          item.isLinetype = item.isLinetype?1:2;
          item.isMobillno = item.isMobillno?1:2;
          item.isMachineTable = item.isMachineTable?1:2;
          item.isRoundInspect = item.isRoundInspect?1:2;

        })

        postAction('/mes-quality/mesQcInspectRuleBymcode/addMesQcInspectRuleBmcFinsp',data).then(res=>{
          if(res.success){
            this.addCPModalVisible = false;
            this.$message.success('新增检验项目成功！');
            this.queryAllInfoById();
            this.loadData();
          }else{
            this.$message.warning(res.msg);
          }
        })

      },
      openDetailBtn(record){
        this.de = record;
        let key=1;
        this.de.mesQcInspectRuleBmcFinspList.forEach(item=>{
          item.key = key;
          key = key+1;
          item.isFirstCheck = item.isFirstCheck?item.isFirstCheck==1?true:false:false;
          item.isLineleaderConfirm = item.isLineleaderConfirm?item.isLineleaderConfirm==1?true:false:false;
          item.isDate = item.isDate?item.isDate==1?true:false:false;
          item.isMcode = item.isMcode?item.isMcode==1?true:false:false;
          item.isLinetype = item.isLinetype?item.isLinetype==1?true:false:false;
          item.isMobillno = item.isMobillno?item.isMobillno==1?true:false:false;
          item.isMachineTable = item.isMachineTable?item.isMachineTable==1?true:false:false;
          item.isRoundInspect = item.isRoundInspect?item.isRoundInspect==1?true:false:false;
          if(item.roundInspectMethod==2){

            if(item.roundInspectFrequency&&item.roundInspectFrequency!=''){
              item.rifLeft = item.roundInspectFrequency.split(':')[0];
              item.rifRight = item.roundInspectFrequency.split(':')[0];
            }

          }

        })
        this.detailVisible=true;
      },
      closeDetailBtn(){
        this.detailVisible=false;
      },

      initAqlNameList(){
        getAction('/mes-quality/mesQcAqlSampleStandard/queryAqlName').then(res=>{
          if(res.success){
            this.aqlNameList = res.data;
          }
        })
      },

      initSimplingMethodList(){
        getAction('/basic-business/sys/dict/queryDictItemsByCode',{dictCode:'rc_inspect_method '}).then(res=>{
          if(res.success){
            this.simplingMethodList = res.data;
            this.simplingMethodMap = this.listToMap(this.simplingMethodList,'id');
          }
        })
      },

      initAqlDataList(){
        getAction('/mes-quality/mesQcAqlSampleStandard/selectAll').then(res=>{
          if(res.success){
            this.aqlDataList = res.data;
            this.aqlDataMap = this.listToMap(this.aqlDataList,'id');
          }
        })
      },

      initCustomerList(supno,supname){
        this.loadingVisible2 = true;
        getAction('/basic-business/auto/baSupinfo/selectAll',{supno:supno,supname:supname}).then(res=>{
          this.loadingVisible2 = false;
          if(res.success){
            this.customerList =res.data;
            this.customerMap  = this.listToMap(this.customerList,'id');
          }
        })
      },
      initInspectTypeList(){
        getAction('/basic-business/sys/dict/queryDictItemsByCode',{dictCode:'inspect_type'}).then(res=>{
          if(res.success){
            this.inspectTypeList = res.data;
            this.inspectTypeMap  = this.listToMap(this.inspectTypeList,'value');
          }
        })
      },
      initProductList(data){
        this.loadingVisible=true;
        getAction('/basic-business/auto/baCpinfoMain/queryLimit',data).then(res=>{
          this.loadingVisible=false;
          if(res.success){
            this.productList = res.data;
            this.productMap = this.listToMap(this.productList,'id');
          }
        })
      },

      clickTimePicker(record){
        this.currentKey = record.key;
      },

      firstCheckOnSelectChange(selectedRowKeys, selectionRows){
        this.firstCheckSelectRowKeys = selectedRowKeys;
        this.firstCheckSelectRows = selectionRows;
      },
      isFirstCheckChange(record){
        let key = record.key;
        if(this.firstCheckTableData[key-1]){
          this.firstCheckTableData[key-1].isFirstCheck = this.firstCheckTableData[key-1].isFirstCheck?false:true;
          if(this.firstCheckTableData[key-1].isFirstCheck){
            this.firstCheckTableData[key-1].isMcode = true;
            this.firstCheckTableData[key-1].isLineleaderConfirm = true;
            this.firstCheckTableData[key-1].isDate = true;
            this.firstCheckTableData[key-1].isLinetype = true;
          }else{
            this.firstCheckTableData[key-1].isMcode = false;
            this.firstCheckTableData[key-1].isLineleaderConfirm = false;
            this.firstCheckTableData[key-1].isDate = false;
            this.firstCheckTableData[key-1].isLinetype = false;
          }
        }



      },

      addLine(){
        this.addcpLoding = true;
        this.addCPModalVisible =true;
        this.readyAddCPSelectRowKeys = [];
        this.readyAddCPSelectRows = [];
        this.inspectTypeForOneTwo2(this.form.inspectionType);
      },

      isLineleaderConfirmChange(record){
        let key = record.key;
        if(this.firstCheckTableData[key-1]){
          this.firstCheckTableData[key-1].isLineleaderConfirm = this.firstCheckTableData[key-1].isLineleaderConfirm?false:true;
        }
      },

      isDateChange(record){
        let key = record.key;
        if(this.firstCheckTableData[key-1]){
          this.firstCheckTableData[key-1].isDate = this.firstCheckTableData[key-1].isDate?false:true;
        }
      },

      isMcodeChange(record){
        let key = record.key;
        if(this.firstCheckTableData[key-1]){
          this.firstCheckTableData[key-1].isMcode = this.firstCheckTableData[key-1].isMcode?false:true;
        }
      },

      isLinetypeChange(record){
        let key = record.key;
        if(this.firstCheckTableData[key-1]){
          this.firstCheckTableData[key-1].isLinetype = this.firstCheckTableData[key-1].isLinetype?false:true;
        }
      },

      isMobillnoChange(record){
        let key = record.key;
        if(this.firstCheckTableData[key-1]){
          this.firstCheckTableData[key-1].isMobillno = this.firstCheckTableData[key-1].isMobillno?false:true;
        }
      },

      isMachineTableChange(record){
        let key = record.key;
        if(this.firstCheckTableData[key-1]){
          this.firstCheckTableData[key-1].isMachineTable = this.firstCheckTableData[key-1].isMachineTable?false:true;
        }
      },


      isRoundInspectChange(record){
        let key = record.key;
        if(this.firstCheckTableData[key-1]){
          this.firstCheckTableData[key-1].isRoundInspect = this.firstCheckTableData[key-1].isRoundInspect?false:true;
        }
      },

      fNumberChange(record){
        let key = record.key;

        if(this.firstCheckTableData[key-1]){
          if(this.firstCheckTableData[key-1].roundInspectFrequency==''||this.firstCheckTableData[key-1].roundInspectFrequency<1){
            this.firstCheckTableData[key-1].roundInspectFrequency = 1;
          }
        }
      },

      fNumberChange1(record){
        let key = record.key;

        if(this.firstCheckTableData[key-1]){
          if(!this.firstCheckTableData[key-1].rifLeft||this.firstCheckTableData[key-1].rifLeft==''){
           /* console.log('one type')
            this.firstCheckTableData[key-1].rifLeft = 1;*/

            Vue.set(this.firstCheckTableData[key-1],'rifLeft',1);
          }else{
            this.firstCheckTableData[key-1].rifLeft = parseInt(this.firstCheckTableData[key-1].rifLeft);
            if(this.firstCheckTableData[key-1].rifLeft<1){
             /* console.log('twoType')
              this.firstCheckTableData[key-1].rifLeft = 1;*/
              Vue.set(this.firstCheckTableData[key-1],'rifLeft',1);
            }
          }
        }
      },

      fNumberChange2(record){
        let key = record.key;
        if(this.firstCheckTableData[key-1]){
          if(!this.firstCheckTableData[key-1].rifRight||this.firstCheckTableData[key-1].rifRight==''){

            Vue.set(this.firstCheckTableData[key-1],'rifRight',1);
          }else{
            this.firstCheckTableData[key-1].rifRight = parseInt(this.firstCheckTableData[key-1].rifRight);
            if(this.firstCheckTableData[key-1].rifRight < 1){

              Vue.set(this.firstCheckTableData[key-1],'rifRight',1);
            }
          }
        }
      },


      productSearch(value){

          this.initProductList({mcode:value+''});
      },

      productChange(record){

        return {
          on: {
            click: () => {
             let value = record.id;
              this.form.mcode ='';
              this.form.mname ='';
              this.form.mid = value;

              if(this.productMap[value]){
                this.form.mcode = this.productMap[value].mcode;
                this.form.mname = this.productMap[value].mname;
                this.form.productOneTypeCode='';
                this.form.productOneType='';
                this.form.productTwoTypeCode='';
                this.form.productTwoType='';
                this.form.productThreeTypeCode='';
                this.form.productThreeType='';
                this.getFSTByMcode(this.form.mcode);
              }
            },
          },
        };




      },

      delCheckProjectWhenEdit(){
        let result = '';

        this.xunCheckSelectRows.forEach(item=>{
          result = result + item.id +',';
        })
        result = result.substring(0,result.length-1);

        deleteAction('/mes-quality/mesQcInspectRuleBymcode/deleteBatchMesQcInspectRuleBmcFinsp?ids='+result).then(res=>{
          if(res.success){
            this.$message.success('删除成功！')
            this.queryAllInfoById();
          }else{
            this.$message.warning(res.msg);
          }
        })

      },

      queryAllInfoById(){
        getAction('/mes-quality/mesQcInspectRuleBymcode/selectById/'+this.editP.id).then(res=>{
          if(res.success){
            this.openEditBtn(res.data);
          }else{
            this.$message.warning(res.msg);
          }
        })
      },


      queryCheckRuleParam(){

        let productThreeCode = this.form.productThreeTypeCode?this.form.productThreeTypeCode:'';
        let InspectType = this.form.inspectionType;
        getAction('/mes-quality/mesQcInspectRuleBytype/selectByProThreeAndInspectType?productThreeCode='+productThreeCode+'&InspectType='+InspectType).then(res=>{
          if(res.success){
              if(res.data){
                let data= res.data;

                Vue.set(this.form,'inspectAttribute',data.inspectAttribute);
                Vue.set(this.form,'tightCoefficient',data.tightCoefficient);
                Vue.set(this.form,'isDynamicRegulation',data.isDynamicRegulation);
                Vue.set(this.form,'normalN1',data.normalN1);
                Vue.set(this.form,'passThroughN2',data.passThroughN2);
                Vue.set(this.form,'isNeedCustoutrc',data.isNeedCustoutrc);
                Vue.set(this.form,'simplingMethod',data.simplingMethod);
                Vue.set(this.form,'aqlSimpleStandardName',data.aqlSimpleStandardName);
                if(data.simplingMethod==1){
                  let normalSimplingQty= data.normalSimplingQty;
                  if(normalSimplingQty.split(':').length>1){
                   /* this.form.normalSimplingQtyType = 2;
                    this.form.normalSimplingQty = 0;
                    this.form.normalSimplingQtyLeft = normalSimplingQty.split(':')[0];
                    this.form.normalSimplingQtyRight = normalSimplingQty.split(':')[1];*/
                    Vue.set(this.form,'normalSimplingQtyType',2);
                    Vue.set(this.form,'normalSimplingQty',0);
                    Vue.set(this.form,'normalSimplingQtyLeft',normalSimplingQty.split(':')[0]);
                    Vue.set(this.form,'normalSimplingQtyRight',normalSimplingQty.split(':')[1]);


                  }else{
                   /* this.form.normalSimplingQtyType = 1;
                    this.form.normalSimplingQty = parseInt(normalSimplingQty);*/
                    Vue.set(this.form,'normalSimplingQtyType',1);
                    Vue.set(this.form,'normalSimplingQty',parseInt(data.normalSimplingQty));
                  }
                }

              }else{
                /*inspectAttribute:1,
                        tightCoefficient:2,
                        isDynamicRegulation:true,
                        normalN1:0,
                        passThroughN2:0,
                        isNeedCustoutrc:false,
                        simplingMethod:1,
                        normalSimplingQtyType:1,
                        normalSimplingQty:0,
                        normalSimplingQtyLeft:0,
                        normalSimplingQtyRight:0,
                        aqlSimpleId:'',*/
                Vue.set(this.form,'inspectAttribute',3);
                Vue.set(this.form,'tightCoefficient','');
                Vue.set(this.form,'isDynamicRegulation',true);
                Vue.set(this.form,'normalN1','');
                Vue.set(this.form,'passThroughN2','');
                Vue.set(this.form,'isNeedCustoutrc',false);
                Vue.set(this.form,'simplingMethod',1);
                Vue.set(this.form,'normalSimplingQtyType',1);
                Vue.set(this.form,'normalSimplingQty','');
                Vue.set(this.form,'normalSimplingQtyLeft',0);
                Vue.set(this.form,'normalSimplingQtyRight',0);
                Vue.set(this.form,'aqlSimpleStandardName','');
              }
          }
        })
      },


      tightCoefficientChange(){

      },
      simplingMethodSelectChange(){
        this.form.aqlSimpleId='';
        this.form.normalSimplingQty=0;

      },
      normalSimplingQtyTypeChange(){
        if(this.form.normalSimplingQtyType==1){
          this.form.normalSimplingQty= 0;
        }else{
          this.form.normalSimplingQtyLeft = 0;
          this.form.normalSimplingQtyRight = 0;
        }
      },
      numberChange1(){

      },
      sqlSimpleSelectChange(){
        let aqlSimpleId = this.form.aqlSimpleId;
        if(aqlSimpleId){
          let id = parseInt(aqlSimpleId.split('-')[0]);
          if(this.aqlDataMap[id]){
            this.form.normalSimplingQty = this.aqlDataMap[id].sampleQty;
          }
        }

      },
      numberChange2(){
        if(this.form.normalSimplingQtyLeft==''){
          this.form.normalSimplingQtyLeft = 0;
        }
      },
      numberChange3(){
        if(this.form.normalSimplingQtyRight==''){
          this.form.normalSimplingQtyRight = 0;
        }
      },
      numberChange4(){

      },
      numberChange5(){

      },

      customerSearch1(value){
        this.initCustomerList(value+'','');
      },
      customerSearch2(value){
        this.initCustomerList('',value+'');
      },

      deleteBtn(id){
        deleteAction('/mes-quality/mesQcInspectRuleBymcode/delete/'+id).then(res=>{
          if(res.success){
            this.$message.success("删除成功");
            this.loadData();
          }else{
            this.$message.warning("删除失败");
          }
        })
      },



      moment,
      changeTime (val, dateStrings, type) {
        if (type === 'startTime') {
          this.firstCheckTableData[this.currentKey-1].startTime = moment(dateStrings, 'HH:mm')
        } else {
          this.firstCheckTableData[this.currentKey-1].endTime = moment(dateStrings, 'HH:mm')
        }
      },
      getDisabledHours () {
        let hours = []
        let time = this.firstCheckTableData[this.currentKey-1].startTime._i
        let timeArr = time.split(':')
        for (var i = 0; i < parseInt(timeArr[0]); i++) {
          hours.push(i)
        }
        return hours
      },
      getDisabledMinutes (selectedHour) {
        let time = this.firstCheckTableData[this.currentKey-1].startTime._i
        let timeArr = time.split(':')
        let minutes = []
        if (selectedHour == parseInt(timeArr[0])) {
          for(var i = 0; i < parseInt(timeArr[1]); i++) {
            minutes.push(i)
          }
        }
        return minutes
      },
      getDisabledSeconds (selectedHour, selectedMinute) {
        let time = this.firstCheckTableData[this.currentKey-1].startTime._i
        let timeArr = time.split(':')
        let second = []
        if (selectedHour == parseInt(timeArr[0]) && selectedMinute == parseInt(timeArr[1])) {
          for(var i = 0; i <= parseInt(timeArr[2]); i++) {
            second.push(i)
          }
        }
        return second
      },

      inspectionTypeChange(){
        this.form.custid = '';
        this.form.custno = '';
        this.form.custname = '';

        let inspectionType = this.form.inspectionType ;
        switch (inspectionType) {
            case 1:
            case 2:
              this.firstCheckSelectRowKeys = [];
              this.firstCheckSelectRows = [];
              this.inspectTypeForOneTwo(inspectionType);
                break;

            default:
              this.queryCheckRuleParam();
              break;
        }

      },

      inspectTypeForOneTwo(inspectType){
        let mcode = this.form.mcode;
        if(mcode&&mcode!=''){
          getAction('/mes-quality/mesQcInspectRuleBymcode/selectProcessTwoByMcode?mcode='+mcode).then(res=>{
            if(res.success){
              let list = res.data;
              let key = 1;
              list.forEach(item=>{
                item.key =  key;
                key = key+1;
                item.isFirstCheck = item.isFirstCheck?item.isFirstCheck==1?true:false:false;
                item.isLineleaderConfirm = item.isLineleaderConfirm?item.isLineleaderConfirm==1?true:false:false;
                item.isDate = item.isDate?item.isDate==1?true:false:false;
                item.isMcode = item.isMcode?item.isMcode==1?true:false:false;
                item.isLinetype = item.isLinetype?item.isLinetype==1?true:false:false;
                item.isMobillno = item.isMobillno?item.isMobillno==1?true:false:false;
                item.isMachineTable = item.isMachineTable?item.isMachineTable==1?true:false:false;
                item.isRoundInspect = item.isRoundInspect?item.isRoundInspect==1?true:false:false;


                if(item.roundInspectMethod==1){
                  item.rifLeft = 0;
                  item.rifRight = 0;
                }else if(item.roundInspectMethod==2){
                  let roundInspectFrequency = item.roundInspectFrequency;
                  item.rifLeft = parseInt(roundInspectFrequency.split(':')[0]);
                  item.rifRight = parseInt(roundInspectFrequency.split(':')[1]);
                  item.roundInspectFrequency = 0;
                }

                item.startTime = item.roundInspectTimequantum?moment(item.roundInspectTimequantum.split('-')[0],'HH:mm'):moment('08:00','HH:mm');
                item.endTime = item.roundInspectTimequantum?moment(item.roundInspectTimequantum.split('-')[1],'HH:mm'):moment('17:00','HH:mm');

              })
              console.log(list)
              this.firstCheckTableData = list;
              this.firstCheckTableDataMap = this.listToMap(list,'key');
            }else{
              this.$message.warning(res.msg)
            }
          })
        }




      },

      inspectTypeForOneTwo2(inspectType){
        this.addcpLoding = true;
        let mcode = this.form.mcode;
        if(mcode&&mcode!=''){
         /* getAction('/mes-quality/mesQcFirstroundInspectRule/selectByFirstTourInspect/'+inspectType).then(res=>{
            if(res.success){*/
          getAction('/mes-quality/mesQcInspectRuleBymcode/selectProcessTwoByMcode?mcode='+mcode).then(res=>{
            if(res.success){
              /*let list = res.data;
              let key = 1;
              list.forEach(item=>{
                item.key =  key;
                key = key+1;
              })*/

              let list = res.data;
              let key = 1;
              list.forEach(item=>{
                item.key =  key;
                key = key+1;
                item.isFirstCheck = item.isFirstCheck?item.isFirstCheck==1?true:false:false;
                item.isLineleaderConfirm = item.isLineleaderConfirm?item.isLineleaderConfirm==1?true:false:false;
                item.isDate = item.isDate?item.isDate==1?true:false:false;
                item.isMcode = item.isMcode?item.isMcode==1?true:false:false;
                item.isLinetype = item.isLinetype?item.isLinetype==1?true:false:false;
                item.isMobillno = item.isMobillno?item.isMobillno==1?true:false:false;
                item.isMachineTable = item.isMachineTable?item.isMachineTable==1?true:false:false;
                item.isRoundInspect = item.isRoundInspect?item.isRoundInspect==1?true:false:false;


                if(item.roundInspectMethod==1){
                  item.rifLeft = 0;
                  item.rifRight = 0;
                }else if(item.roundInspectMethod==2){
                  let roundInspectFrequency = item.roundInspectFrequency;
                  item.rifLeft = parseInt(roundInspectFrequency.split(':')[0]);
                  item.rifRight = parseInt(roundInspectFrequency.split(':')[1]);
                  item.roundInspectFrequency = 0;
                }

                item.startTime = item.roundInspectTimequantum?moment(item.roundInspectTimequantum.split('-')[0],'HH:mm'):moment('08:00','HH:mm');
                item.endTime = item.roundInspectTimequantum?moment(item.roundInspectTimequantum.split('-')[1],'HH:mm'):moment('17:00','HH:mm');

              })
              this.readyAddCPdata = list;
              this.readyAddCPdataMap = this.listToMap(list,'key');



            }
          }).then(res=>{
            this.addcpLoding = false
          })
        }


      },

      onXunCheckSelectChange(selectedRowKeys, selectionRows){
        this.xunCheckSelectRowKeys = selectedRowKeys;
        this.xunCheckSelectRows = selectionRows;
      },




      customerChange1(value){
        console.log(value)
        this.form.custid = value;
        this.form.custno = '';
        this.form.custname = '';

        if(this.customerMap[value]){
          let item = this.customerMap[value];
          this.form.custno = item.supno;
          this.form.custname = item.supname;
        }
      },


      getFSTByMcode(mcode){
        this.loadingVisible1=true;
        getAction('/basic-business/auto/baCpinfoMain/select/by/mcode',{mcode:mcode}).then(res=>{
          this.loadingVisible1=false;
          if(res.success){
            let data = res.data;
            if(res.data){
              this.form.productOneTypeCode=data.productOneTypeCode?data.productOneTypeCode:'';
              this.form.productOneType=data.productOneType?data.productOneType:'';
              this.form.productTwoTypeCode=data.productTwoTypeCode?data.productTwoTypeCode:'';
              this.form.productTwoType=data.productTwoType?data.productTwoType:'';
              this.form.productThreeTypeCode=data.productThreeTypeCode?data.productThreeTypeCode:'';
              this.form.productThreeType=data.productThreeType?data.productThreeType:'';

              let inspectionType = this.form.inspectionType;
              switch (inspectionType) {
                case 1:
                case 2:
                  this.inspectTypeForOneTwo(inspectionType);
                  break;
                default:
                  this.queryCheckRuleParam();
                  break;
              }
            }
          }
        })
      },



      openAddBtn(){

          this.formDataReset();

        this.pModalVisible = true;
        this.currentState =1;

        this.pTitle = '新增';
      },

      openEditBtn(data){
        this.pModalVisible = true;
        this.currentState =2;
        this.pTitle = '编辑';

        this.editP = data;
        this.xunCheckSelectRowKeys = [];
        this.xunCheckSelectRows = [];
        console.log(data)
        this.form={
          inspectionType : data.inspectionType,
          status:parseInt(data.status),
          mid:data.midStr,
          mcode:data.mcode,
          mname:data.mname,
          productOneType:data.productOneType,
          productOneTypeCode:data.productOneTypeCode,
          productTwoType:data.productTwoType,
          productTwoTypeCode:data.productTwoTypeCode,
          productThreeType:data.productThreeType,
          productThreeTypeCode:data.productThreeTypeCode,
        }

        let inspectionType = data.inspectionType;
        let resultList = [];
        switch (inspectionType) {
            case 1:
            case 2:
              let key = 1;
              console.log(data.mesQcInspectRuleBmcFinspList)
              data.mesQcInspectRuleBmcFinspList.forEach(item=>{
                item.key = key;
                key = key+1;
                item.isFirstCheck = item.isFirstCheck?item.isFirstCheck==1?true:false:false;
                item.isLineleaderConfirm = item.isLineleaderConfirm?item.isLineleaderConfirm==1?true:false:false;
                item.isDate = item.isDate?item.isDate==1?true:false:false;
                item.isMcode = item.isMcode?item.isMcode==1?true:false:false;
                item.isLinetype = item.isLinetype?item.isLinetype==1?true:false:false;
                item.isMobillno = item.isMobillno?item.isMobillno==1?true:false:false;
                item.isMachineTable = item.isMachineTable?item.isMachineTable==1?true:false:false;
                item.isRoundInspect = item.isRoundInspect?item.isRoundInspect==1?true:false:false;

                item.startTime = moment(item.roundInspectTimequantum.split('-')[0],'HH:mm');
                item.endTime = moment(item.roundInspectTimequantum.split('-')[1],'HH:mm');
                if(item.roundInspectMethod==2){

                  if(item.roundInspectFrequency&&item.roundInspectFrequency!=''){

                    Vue.set(item,'rifLeft',parseInt(item.roundInspectFrequency.split(':')[0]))
                    Vue.set(item,'rifRight',parseInt(item.roundInspectFrequency.split(':')[1]))

                  }

                }

              })

              resultList = data.mesQcInspectRuleBmcFinspList;
              this.firstCheckTableData = resultList;
              break;
              case 5:
              default:
                Vue.set(this.form,'custid',data.custid+'');
                Vue.set(this.form,'custno',data.custno);
                Vue.set(this.form,'custname',data.custname);

                this.customerSearch1(data.custno)
                this.customerChange1(data.custid+'')


                Vue.set(this.form,'inspectAttribute',data.inspectAttribute);

                Vue.set(this.form,'tightCoefficient',data.tightCoefficient);
                Vue.set(this.form,'isDynamicRegulation',data.isDynamicRegulation==1?true:false);
                Vue.set(this.form,'normalN1',data.normalN1);
                Vue.set(this.form,'passThroughN2',data.passThroughN2);
                Vue.set(this.form,'isNeedCustoutrc',data.isNeedCustoutrc);
                Vue.set(this.form,'simplingMethod',data.simplingMethod);
                Vue.set(this.form,'aqlSimpleStandardName',data.aqlSimpleStandardName);
                if(data.simplingMethod==1){
                  let normalSimplingQty= data.normalSimplingQty;
                  if(normalSimplingQty.split(':').length>1){
                    Vue.set(this.form,'normalSimplingQtyType',2);
                    Vue.set(this.form,'normalSimplingQty',0);
                    Vue.set(this.form,'normalSimplingQtyLeft',normalSimplingQty.split(':')[0]);
                    Vue.set(this.form,'normalSimplingQtyRight',normalSimplingQty.split(':')[1]);


                  }else{
                    Vue.set(this.form,'normalSimplingQtyType',1);
                    Vue.set(this.form,'normalSimplingQty',parseInt(data.normalSimplingQty));
                  }
                }


                  break;
        }




      },

      numberCheck(val){
        // isNaN()函数 把空串 空格 以及NUll 按照0来处理 所以先去除，

        if(val === "" || val ==null){
          return false;
        }
        if(!isNaN(val)){
          //对于空数组和只有一个数值成员的数组或全是数字组成的字符串，isNaN返回false，例如：'123'、[]、[2]、['123'],isNaN返回false,
          //所以如果不需要val包含这些特殊情况，则这个判断改写为if(!isNaN(val) && typeof val === 'number' )

          if(val<=0){
            return false;
          }else{
            return true;
          }
        }

        else{
          return false;
        }
      },




      pModalOk(){
        let data  =this.form;
        let flag = true;

        if(data.inspectionType&&data.inspectionType!=1&&data.inspectionType!=2){
          if(data.simplingMethod==2){
            if(data.aqlSimpleStandardName==''){
              flag = false;
              this.$message.error("请选择AQL抽样标准");
            }
          }
          if(data.inspectAttribute==1){
            if(!this.numberCheck(data.tightCoefficient)){
              flag = false;
              this.$message.error("'加严系数' 值错误");
            }else{
              if(data.tightCoefficient<=1){
                flag = false;
                this.$message.error("'加严系数' 值错误(必须大于1)");
              }
            }
          }

          if(data.isDynamicRegulation){
            if(!this.numberCheck(data.normalN1)){
              flag = false;
              this.$message.error("'动态调整规则-正常（N1）' 值错误");
            }
            if(!this.numberCheck(data.passThroughN2)){
              flag = false;
              this.$message.error("'动态调整直通（N2）' 值错误");
            }
          }

          if(data.simplingMethod==1){
            if(!this.numberCheck(data.normalSimplingQty)){
              flag = false;
              this.$message.error("'正常抽样数量' 值错误");
            }
          }
        }



        if(flag){
          this.$refs.ruleForm.validate(valid => {
            if (valid) {
              if(this.currentState==1){
                this.pAddOperation();
              }else if(this.currentState==2){
                this.pEditOperation();
              }
            } else {
              console.log('error submit!!');
              return false;
            }
          });
        }
      },

      formDataConvert(){
        let data  =this.form;
        let result = {};
        if(this.currentState==2){
          result = this.editP;
        }

        result.inspectionType = data.inspectionType;
        result.status=data.status;
        result.mid=data.mid;
        result.mcode=data.mcode;
        result.mname=data.mname;
        result.productOneType=data.productOneType;
        result.productOneTypeCode=data.productOneTypeCode;
        result.productTwoType=data.productTwoType;
        result.productTwoTypeCode=data.productTwoTypeCode;
        result.productThreeType=data.productThreeType;
        result.productThreeTypeCode=data.productThreeTypeCode;
        let resultList = [];
        switch (data.inspectionType) {
          case 1:
          case 2:
            let rows =[];
            if(this.currentState==1){
              rows =  this.firstCheckSelectRows;
            }else{
              rows = this.firstCheckTableData;
            }


            console.log("rows---")
            console.log(rows)
            rows.forEach(item=>{
              let listItem = item;
              listItem.processOneId = item.processOneId;
              listItem.processOneCode = item.processOneCode;
              listItem.processOneName = item.processOneName;
              listItem.processTwoId = item.processTwoId;
              listItem.processTwoCode = item.processTwoCode;
              listItem.processTwoName = item.processTwoName;

                listItem.isFirstCheck = item.isFirstCheck?1:2;
                listItem.isLineleaderConfirm = item.isLineleaderConfirm?1:2;
                listItem.isDate = item.isDate?1:2;
                listItem.isMcode = item.isMcode?1:2;
                listItem.isLinetype = item.isLinetype?1:2;
                listItem.isMobillno = item.isMobillno?1:2;
                listItem.isMachineTable = item.isMachineTable?1:2;
                listItem.isRoundInspect = item.isRoundInspect?1:2;

                listItem.isRoundInspect = item.isRoundInspect?1:2;
                listItem.roundInspectMethod = item.roundInspectMethod;
                if(item.roundInspectMethod==1){
                  listItem.roundInspectFrequency = item.roundInspectFrequency;
                }else{
                  listItem.roundInspectFrequency = parseInt(item.rifLeft+'')+':'+parseInt(item.rifRight+'');
                }
                /*listItem.roundInspectTimequantum = item.startTime+'-'+item.endTime;*/
                listItem.roundInspectTimequantum = item.startTime._i+'-'+item.endTime._i;

                listItem.rcInspectMethod = item.rcInspectMethod;
                listItem.rcInspectQty = item.rcInspectQty;
                listItem.aqlSimpleStandardName = item.aqlSimpleStandardName;



              resultList.push(listItem)
            })


            break;
          case 5:
              result.custid = data.custid;
              result.custno = data.custno;
              result.custname = data.custname;
              result.isNeedCustoutrc = data.isNeedCustoutrc?1:2;
          default:
            result.inspectAttribute = data.inspectAttribute;
            result.tightCoefficient = data.tightCoefficient;
            result.isDynamicRegulation = data.isDynamicRegulation?1:2;
            result.normalN1 = data.normalN1;
            result.passThroughN2 = data.passThroughN2;
            result.simplingMethod = data.simplingMethod;
            result.aqlSimpleStandardName = data.aqlSimpleStandardName;

            if(data.simplingMethod==1){
              if(data.normalSimplingQtyType==1){
                result.normalSimplingQty = data.normalSimplingQty+'';
              }else{
                result.normalSimplingQty = data.normalSimplingQtyLeft+':'+data.normalSimplingQtyRight;
              }
            }

              break;
        }
        result.mesQcInspectRuleBmcFinspList = resultList;
        return result;
      },

      formDataReset(){

        this.firstCheckTableData=[];
        this.firstCheckTableDataMap=[];
        this.firstCheckSelectRowKeys=[];
        this.firstCheckSelectRows=[];
        this.form={
          inspectionType:'',
          status:1,
          mid:'',
          mcode:'',
          mname:'',
          productOneTypeCode:'',
          productOneType:'',
          productTwoTypeCode:'',
          productTwoType:'',
          productThreeTypeCode:'',
          productThreeType:'',
          custid:'',
          custno:'',
          custname:'',
          inspectAttribute:3,
          tightCoefficient:'',
          isDynamicRegulation:true,
          normalN1:'',
          passThroughN2:'',
          isNeedCustoutrc:false,
          simplingMethod:1,
          normalSimplingQtyType:1,
          normalSimplingQty:'',
          normalSimplingQtyLeft:0,
          normalSimplingQtyRight:0,
          aqlSimpleId:'',
          aqlSimpleStandardName:'',
        }
      },

      pAddOperation(){

        let flag = true;

        if(this.form.inspectionType==1||this.form.inspectionType==2){
          if(this.firstCheckSelectRows.length<1){
            flag = false;
            this.$message.error('请勾选检验规则');
          }
        }

        if(flag){
          let data  =this.formDataConvert();
          postAction('/mes-quality/mesQcInspectRuleBymcode/add',data).then(res=>{
            if(res.success){
              this.pModalVisible = false;
              this.formDataReset();
              this.$message.success("新增成功");
              this.loadData();
            }else{
              this.$message.warning(res.msg);
              this.switchDataReset(data);
            }
          })
        }

      },

      switchDataReset(data){
        data.mesQcInspectRuleBmcFinspList.forEach(item=>{
          item.isFirstCheck = item.isFirstCheck?item.isFirstCheck==1?true:false:false;
          item.isLineleaderConfirm = item.isLineleaderConfirm?item.isLineleaderConfirm==1?true:false:false;
          item.isDate = item.isDate?item.isDate==1?true:false:false;
          item.isMcode = item.isMcode?item.isMcode==1?true:false:false;
          item.isLinetype = item.isLinetype?item.isLinetype==1?true:false:false;
          item.isMobillno = item.isMobillno?item.isMobillno==1?true:false:false;
          item.isMachineTable = item.isMachineTable?item.isMachineTable==1?true:false:false;
          item.isRoundInspect = item.isRoundInspect?item.isRoundInspect==1?true:false:false;
        })
        this.firstCheckSelectRows.forEach(item=>{
          item.isFirstCheck = item.isFirstCheck?item.isFirstCheck==1?true:false:false;
          item.isLineleaderConfirm = item.isLineleaderConfirm?item.isLineleaderConfirm==1?true:false:false;
          item.isDate = item.isDate?item.isDate==1?true:false:false;
          item.isMcode = item.isMcode?item.isMcode==1?true:false:false;
          item.isLinetype = item.isLinetype?item.isLinetype==1?true:false:false;
          item.isMobillno = item.isMobillno?item.isMobillno==1?true:false:false;
          item.isMachineTable = item.isMachineTable?item.isMachineTable==1?true:false:false;
          item.isRoundInspect = item.isRoundInspect?item.isRoundInspect==1?true:false:false;
        })
        this.firstCheckTableData.forEach(item=>{
          item.isFirstCheck = item.isFirstCheck?item.isFirstCheck==1?true:false:false;
          item.isLineleaderConfirm = item.isLineleaderConfirm?item.isLineleaderConfirm==1?true:false:false;
          item.isDate = item.isDate?item.isDate==1?true:false:false;
          item.isMcode = item.isMcode?item.isMcode==1?true:false:false;
          item.isLinetype = item.isLinetype?item.isLinetype==1?true:false:false;
          item.isMobillno = item.isMobillno?item.isMobillno==1?true:false:false;
          item.isMachineTable = item.isMachineTable?item.isMachineTable==1?true:false:false;
          item.isRoundInspect = item.isRoundInspect?item.isRoundInspect==1?true:false:false;
        })
      },

      pEditOperation(){
        let data  =this.formDataConvert();
        console.log(data)
        putAction('/mes-quality/mesQcInspectRuleBymcode/edit',data).then(res=>{
          if(res.success){
            this.pModalVisible = false;
            this.formDataReset();
            this.$message.success("修改成功！");
            this.loadData();
          }else{
            this.$message.warning(res.msg);
            this.switchDataReset(data);
            this.loadData();

          }

        })
      },



      data_dic(text,zi_duan) {/*插槽数据字典*/
         return filterMultiDictText(this.dictOptions[zi_duan], text + "")
      },
      kan_zi_biao(data) {
        console.log('检验类型返回值',data);
        if (data == "1") {
          this.zhi_biao_page = '1';
        } else if (data == "2") {
          this.zhi_biao_page = '2';
        } else if (data == "3" || data == "4") {
          this.zhi_biao_page = '3';
        } else if (data == "5") {
          this.zhi_biao_page ='4';
        }
        console.log('现在子表第:',this.zhi_biao_page,'页');
      },


      readyAddCPOnSelectChange(selectRowKeys,selectRows){
        this.readyAddCPSelectRowKeys = selectRowKeys;
        this.readyAddCPSelectRows = selectRows;
      },

      //确定按钮
      handleSearch(selectedKeys, confirm, dataIndex) {
        confirm();
        this.searchText = selectedKeys[0];
        this.searchedColumn = dataIndex;
      },
      //取消按钮
      handleReset(clearFilters) {
        clearFilters();
        this.searchText = '';
      },
      //确定时间
      handleSearchDate(selectedKeys, confirm, dataIndex) {
        confirm();
        this.searchText = selectedKeys[0];
        this.searchedColumn = dataIndex;
        this.searchQuery()
      },
      // 清除时间
      handleResetDate(clearFilters, begin, end) {
        if (this.queryParam[begin] || this.queryParam[end]) {
          this.queryParam[begin] = ''
          this.queryParam[end] = ''
          clearFilters();
          this.searchText = '';
          this.searchQuery()
        } else {
          clearFilters();
          this.searchText = '';
        }

      },
      getKey() {
        const dataItem = []
        setTimeout(() => {
          this.columns.forEach(item => {
            dataItem.push({ 'text': item.title, 'value': item.dataIndex })
          })
        }, 100)
        return dataItem
      },
      //
      getControl(dic) {
        const dataItem = []
        initDictOptions(dic).then((res) => {
          res.data.forEach(item => {
            dataItem.push({ 'text': item.text, 'value': item.value })
          })
        })
        return dataItem
      },

      setdefColumns() {
        if (this.columns.length > 13) {
          let arrLength = this.columns.length - 1
          this.columns.forEach((item, index) => {
            if(index>0){
              item["width"] = 130
            }

          })
          this.columns[arrLength]['fixed'] = 'right'
          this.columns[arrLength-1]['fixed'] = 'right'
          this.columns[0]['fixed'] = 'left'
          this.columns[1]['fixed'] = 'left'
        }
      },
      initColumns() {
        //权限过滤（列权限控制时打开，修改第二个参数为授权码前缀）
        //this.defColumns = colAuthFilter(this.defColumns,'testdemo:');

        var key = this.$route.name + ":colsettings";
        let colSettings = Vue.ls.get(key);
        if (colSettings == null || colSettings == undefined) {
          let allSettingColumns = [];
          this.defColumns.forEach(function (item, i, array) {
            allSettingColumns.push(item.dataIndex);
          })
          this.settingColumns = allSettingColumns;
          this.columns = this.defColumns;
        } else {
          this.settingColumns = colSettings;
          const cols = this.defColumns.filter(item => {
            if (item.key == 'rowIndex' || item.dataIndex == 'action') {
              return true;
            }
            if (colSettings.includes(item.dataIndex)) {
              return true;
            }
            return false;
          })
          this.columns = cols;
        }
      },
      //列设置更改事件
      onColSettingsChange(checkedValues) {
        var key = this.$route.name + ":colsettings";
        Vue.ls.set(key, checkedValues, 7 * 24 * 60 * 60 * 1000)
        this.settingColumns = checkedValues;
        const cols = this.defColumns.filter(item => {
          if (item.key == 'rowIndex' || item.dataIndex == 'action') {
            return true
          }
          if (this.settingColumns.includes(item.dataIndex)) {
            return true
          }
          return false
        })
        this.columns = cols;
      },
      //高级查询方法
      handleSuperQuery(arg) {
        if (!arg) {
          this.superQueryParams = ''
          this.superQueryFlag = false
        } else {
          this.superQueryFlag = true
          this.superQueryParams = JSON.stringify(arg)
        }
        this.loadData()
      },
      // 获取查询条件
      getQueryParams() {
        let sqp = {}
        if (this.superQueryParams) {
          sqp['superQueryParams'] = encodeURI(this.superQueryParams)
        }
        var param = Object.assign(sqp, this.queryParam, this.isorter);
        param.field = this.getQueryField();
        param.pageNo = this.ipagination.current;
        param.limit = this.ipagination.pageSize;
        return filterObj(param);
      },
      initDictConfig() {
        initDictOptions('inspect_type').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'inspectionType', res.data)
          }
        })
        initDictOptions('mes_status').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'status', res.data)
          }
        })
      },
      clickThenSelect(record) {
        return {
          on: {
            click: () => {
              if(record.id){
                console.log(record.id)
                this.rowId = record.id;
                //this.onSelectChange(record.id.split(","), [record]);
              }

            },
          },
        };
      },
      setRowClassName(record){
        return record.id === this.rowId ? 'clickRowStyl' : '';
      },
      onClearSelected() {
        this.selectedRowKeys = [];
        this.selectionRows = [];
      },
      onSelectChange(selectedRowKeys, selectionRows) {
        this.selectedRowKeys = selectedRowKeys;
        this.selectionRows = selectionRows;
      },
      loadData(arg) {
        if (!this.url.list) {
          this.$message.error('请设置url.list属性!')
          return
        }
        // 加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1
        }
        var params = this.getQueryParams() // 查询条件
        this.loading = true
        getAction(this.url.list, params).then((res) => {
          if (res.success) {
            this.dataSource = res.data.records
            this.ipagination.total = res.data.total
          }
          if (res.code === 510) {
            this.$message.warning(res.msg)
          }
        }).then(res=>{
          this.loading = false
        })
      },

      // 弹出窗组件
      showDemoModal() {
        this.$refs.modalCompon.modalShow();
      },
      // 点击btn获取数据
      btnGetData(tableName, title) {
        getAction(`${this.url.getColumns}`, {
          tableName: tableName
        }).then(
          res => {
            if (res.code == 0) {
              this.queryInfo = res.data.columns
              this.title = title
              this.dictOptions = res.data.dictOptions
              this.showDemoModal()
            } else {
              this.$message.warning(res.msg);
            }
          }
        )
      },

      //筛选分组
      getGroupTag(arrList) {
        let arr = [];
        var map = {},
          dest = [];
        arrList.forEach((item, index) => {
          if (item.groupTag) {
            arr.push(item);
          }
        });
        for (var i = 0; i < arr.length; i++) {
          var ai = arr[i];
          if (!map[ai.groupTag]) {
            dest.push({
              groupTag: ai.groupTag,
              name: ai.groupName,
              data: [ai]
            });
            map[ai.groupTag] = ai;
          } else {
            for (var j = 0; j < dest.length; j++) {
              var dj = dest[j];
              if (dj.groupTag == ai.groupTag) {
                dj.data.push(ai);
                break;
              }
            }
          }
        }
        this.groupTag = dest
        console.log(dest);
      },
      showLinkButton(item, record) {
        let btn = new ButtonExpHandler(item.exp, record);
        return btn.show;
      },
      initButtonList() {
        getAction(`${this.url.getColumns}8ac49ec7733bce4801734b45520400ea`).then((res) => {
          console.log("--获取自定义按钮->>", res);
          if (res.success) {
            this.code = res.data.code;
            this.initCgButtonList(res.data.cgButtonList);
            this.initCgEnhanceJs(res.data.enhanceJs);
            this.getGroupTag(res.data.cgButtonList);
          } else {
            this.$message.warning(res.msg)
          }
        })
      },
      initCgEnhanceJs(enhanceJs) {
        //console.log("--onlineList-js增强",enhanceJs)
        if (enhanceJs) {
          let Obj = eval("(" + enhanceJs + ")");
          this.EnhanceJS = new Obj(getAction, postAction, deleteAction);
          this.cgButtonJsHandler('created')
        } else {
          this.EnhanceJS = ''
        }
      },
      initCgButtonList(btnList) {
        let linkArr = []
        let buttonArr = []
        if (btnList && btnList.length > 0) {
          for (let i = 0; i < btnList.length; i++) {
            let temp = btnList[i]
            if (temp.buttonStyle == 'button') {
              buttonArr.push(temp)
            } else if (temp.buttonStyle == 'link') {
              linkArr.push(temp)
            }
          }
        }
        this.cgButtonLinkList = [...linkArr]
        this.cgButtonList = [...buttonArr]
        console.log("链接增强", this.cgButtonLinkList);
      },
      cgButtonJsHandler(buttonCode) {
        if (this.EnhanceJS[buttonCode]) {
          this.EnhanceJS[buttonCode](this)
        }
      },
      cgButtonActionHandler(buttonCode) {
        //处理自定义button的 需要配置该button自定义sql
        if (!this.selectedRowKeys || this.selectedRowKeys.length == 0) {
          this.$message.warning("请先选中一条记录")
          return false
        }
        if (this.selectedRowKeys.length > 1) {
          this.$message.warning("请只选中一条记录")
          return false
        }
        let params = {
          formId: this.code,
          buttonCode: buttonCode,
          dataId: this.selectedRowKeys[0]
        }
        console.log("自定义按钮请求后台参数：", params)
        postAction(this.url.buttonAction, params).then(res => {
          if (res.success) {
            this.loadData()
            this.$message.success("处理完成!")
          } else {
            this.$message.warning("处理失败!")
          }
        })

      },
      cgButtonLinkHandler(record, buttonCode, optType) {
        if (optType == "js") {
          if (this.EnhanceJS[buttonCode]) {
            this.EnhanceJS[buttonCode](this, record)
          }
        } else if (optType == "action") {
          let params = {
            formId: this.code,
            buttonCode: buttonCode,
            dataId: record.id
          }
          console.log("自定义按钮link请求后台参数：", params)
          postAction(this.url.buttonAction, params).then(res => {
            if (res.success) {
              this.loadData()
              this.$message.success("处理完成!")
            } else {
              this.$message.warning("处理失败!")
            }
          })
        }
      },

    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
  /deep/.clickRowStyl td{
    background:#00b4ed !important;
  }

  /deep/.ant-table-tbody.clickRowStyl:hover>td {
    background-color:#00b4ed
  }
</style>